How Can I change the range of a excel chart using actxserver?

5 次查看(过去 30 天)
This is my code:
excel = actxserver('Excel.Application');
excel.Visible = true;
excel.DisplayAlerts = false;
filename13 = 'C:\Dropbox\Idenglobal\Comparacion peers.xlsx';
pee = excel.Workbooks.Open(filename13);
peesheet = pee.Sheets.Item('Shortlist Credit Suisse');
In that sheet there is only a chart whith datas in the range "Q2:W67" . I would like to extend this range to "Q2:W69". How Can I do? Many thanks!!!

采纳的回答

Manish Annappa
Manish Annappa 2017-5-18
编辑:Manish Annappa 2017-5-18
As per the description, you would like to change the data range for an Excel Chart using actxserver in MATLAB. Below is a code snippet that achieves the same.
excel = actxserver('Excel.Application');
excel.Visible = true;
excel.DisplayAlerts = false;
filename13 = 'C:\Dropbox\Idenglobal\Comparacion peers.xlsx';
pee = excel.Workbooks.Open(filename13);
peesheet = pee.Sheets.Item('Sheet1');
pC = peesheet.ChartObjects(1).Chart
pC.SeriesCollection(1).Values = peesheet.Range('W2:W69');
pC.SeriesCollection(1).XValues = peesheet.Range('Q2:Q69');
In the above code snippet Values corresponds to Y axis range of values. Similarly XValues corresponds to X axis range of values. By changing the range to 69, the previous range will be reset.
Also,I am assuming this chart will be the first chart in the Excel sheet selected (peesheet.ChartObjects(1).Chart).
Refer to the link below for more information on Series object properties: https://msdn.microsoft.com/en-us/library/office/ff838988.aspx

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by