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

조회 수: 5 (최근 30일)
Adriano
Adriano 2017년 5월 16일
댓글: Adriano 2017년 5월 19일
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by