Insert Chart into Multiple Excel sheets
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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;
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!