Excel Chart with 2 X-axis through matlab

조회 수: 1 (최근 30일)
Moh
Moh 2014년 11월 24일
편집: Moh 2014년 11월 28일
I want to make a program that will make an Excel chart with 2 X-axis and Y-axis. how can I add the second X-axis?
my second X-axis is 'Sheet2', C3: C ...
here is my code
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(outname);
% Get neu Worksheets object
WS = WB.Worksheets;
WS.Add([], WS.Item(WS.Count));
Sheet=WB.Worksheets.Item('Sheet2');
Charts = WB.Charts;
Chart = invoke(Charts,'Add');
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(1).Name = 'Temberatur';
Excel.ActiveChart.SeriesCollection(1).XValues = Sheet.Range(strcat('B3:B',num2str(C)));
Excel.ActiveChart.SeriesCollection(1).Values = Sheet.Range(strcat('A3:A',num2str(C)));
% Setting the Chart Sheet Title & Chart Title.
Excel.ActiveChart.HasTitle = 1;
Excel.ActiveChart.ChartTitle.Characters.Text = 'Temperature';
Excel.ActiveChart.Name = 'Temperatur';
% Setting the (X-Axis) and (Y-Axis) titles.
ChartAxes = invoke(Chart,'Axes',1);
set(ChartAxes,'HasTitle',1);
set(ChartAxes.AxisTitle,'Caption','Temperature /°C');
ChartAxes = invoke(Chart,'Axes',2);
set(ChartAxes,'HasTitle',2);
set(ChartAxes.AxisTitle,'Caption','Depth /m');
Excel.ActiveChart.ChartType = 65;
% Setting the (Y-Axis) Scale
Excel.ActiveChart.Axes(2).Select;
Excel.ActiveChart.Axes(2).MinimumScale = 0;
Excel.ActiveChart.Axes(2).MaximumScale = max(handles.tiefe(:,C));
Excel.ActiveChart.Axes(2).ReversePlotOrder = true;

채택된 답변

Moh
Moh 2014년 11월 28일
편집: Moh 2014년 11월 28일
I have found the solution with
Excel.ActiveChart.ChartType = 65;
can not make 2 X-axis . I did that on ChartType = 73 and worked very well
Here the list of chart type
hier ist mein end Code
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(outname);
% Get neu Worksheets object
WS = WB.Worksheets;
WS.Add([], WS.Item(WS.Count));
Sheet=WB.Worksheets.Item('Ergebnis');
Charts = WB.Charts;
Chart = invoke(Charts,'Add');
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(1).Name = 'Temperatur der Erdr';
Excel.ActiveChart.SeriesCollection(1).XValues=Sheet.Range(strcat('B3:B',num2str(C)));
Excel.ActiveChart.SeriesCollection(1).Values =Sheet.Range(strcat('A3:A',num2str(C)));
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(2).Name = 'Temperatur der CO2';
Excel.ActiveChart.SeriesCollection(2).XValues=Sheet.Range(strcat('C3:C',num2str(C)));
Excel.ActiveChart.SeriesCollection(2).Values=Sheet.Range(strcat('A3:A',num2str(C)));
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(3).Name = 'Temperatur der Wand';
Excel.ActiveChart.SeriesCollection(3).XValues=Sheet.Range(strcat('I3:I',num2str(C)));
Excel.ActiveChart.SeriesCollection(3).Values=Sheet.Range(strcat('A3:A',num2str(C)));
% Setting the Chart Sheet Title & Chart Title.
Excel.ActiveChart.HasTitle = 1;
Excel.ActiveChart.ChartTitle.Characters.Text = 'Temperatur';
Excel.ActiveChart.Name = 'Temperatur';
% Setting the (X-Axis) and (Y-Axis) titles.
ChartAxes = invoke(Chart,'Axes',1);
set(ChartAxes,'HasTitle',1);
set(ChartAxes.AxisTitle,'Caption','Temperatur /°C');
ChartAxes = invoke(Chart,'Axes',2);
set(ChartAxes,'HasTitle',2);
set(ChartAxes.AxisTitle,'Caption','Tiefe /m');
Excel.ActiveChart.ChartType = 73;
temp=[handles.T,handles.T_E,handles.Twz];
% Setting the (X-Axis) Scale
Excel.ActiveChart.Axes(1).Select;
Excel.ActiveChart.Axes(1).MinimumScale = min(temp(:));
Excel.ActiveChart.Axes(1).MaximumScale = max(temp(:));
% Setting the (Y-Axis) Scale
Excel.ActiveChart.Axes(2).Select;
Excel.ActiveChart.Axes(2).MinimumScale = 0;
Excel.ActiveChart.Axes(2).MaximumScale = max(handles.tiefe(:,C));
Excel.ActiveChart.Axes(2).ReversePlotOrder = true;
WB.Save();
WB.Close;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by