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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by