Insert Chart in Excel with Excel data with Matlab

9 ビュー (過去 30 日間)
Russell
Russell 2014 年 5 月 28 日
編集済み: Walter Roberson 2021 年 5 月 29 日
I would like to apply this chart to all 16 sheets in the workbook. How can I do this?
Excel = actxserver('Excel.Application');
ResultFile = [pwd '\data.xls']; %USER INPUT: name of file within folder Workbook = invoke(Excel.Workbooks,'Open', ResultFile); %Error is apparently here
set(Excel, 'Visible' ,1);
%% Creating Charts
Chart = Excel.ActiveSheet.Shapes.AddChart; Chart.Name = 'ExperimentChart';
ExpChart = Excel.ActiveSheet.ChartObjects('ExperimentChart'); ExpChart.Activate;
try
Series = invoke(Excel.ActiveChart,'SeriesCollection',1); invoke(Series,'Delete'); Series = invoke(Excel.ActiveChart,'SeriesCollection',1); invoke(Series,'Delete'); Series = invoke(Excel.ActiveChart,'SeriesCollection',1); invoke(Series,'Delete');
catch e
end
resultsheet = '1917001.dat';
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries'); NewSeries.XValues = ['=' resultsheet '!A' int2str(3) ':A' int2str(999)]; NewSeries.Values = ['=' resultsheet '!B' int2str(2) ':B' int2str(999)]; NewSeries.Name = ['=' resultsheet '!B' int2str(1) ];
%Chart Style Excel.ActiveChart.ChartType = 'xlXYScatterLinesNoMarkers';
%Set the Axes
% Set the x-axis
Axes = invoke(Excel.ActiveChart,'Axes',1); set(Axes,'HasTitle',1); set(Axes.AxisTitle,'Caption','Time(s)')
% Set the y-axis
Axes = invoke(Excel.ActiveChart,'Axes',2); set(Axes,'HasTitle',1); set(Axes.AxisTitle,'Caption','RPM')
% % Give the Chart a title Excel.ActiveChart.HasTitle = 1; Excel.ActiveChart.ChartTitle.Characters.Text = 'RPM vs. Time';
% Resize the Chart
ExpChart.Width = 350; ExpChart.Height= 200; ExpChart.Left= 300; ExpChart.Top= 50;

回答 (1 件)

Roger Wohlwend
Roger Wohlwend 2014 年 5 月 28 日
Matlab cannot find the Excel file. Make sure that your path and file name are correct.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by