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

5 vues (au cours des 30 derniers jours)
Adriano
Adriano le 16 Mai 2017
Commenté : Adriano le 19 Mai 2017
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!!!

Réponse acceptée

Manish Annappa
Manish Annappa le 18 Mai 2017
Modifié(e) : Manish Annappa le 18 Mai 2017
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

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by