How do I set the 'HasAxis' property of my Excel Chart object using ActiveX in MATLAB 7.11 (R2010b)?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 3 Dez. 2010
Bearbeitet: MathWorks Support Team
am 23 Jun. 2021
The 'HasAxis' property is used to specify whether Excel will display the primary or secondary category, series, or value axes on a chart.
The property requires that the xlAxisType and xlAxisGroup arguments are specified when the property is accessed.
How do I do that using the ACTXCONTROL ActiveX support in MATLAB?
Information about 'HasAxis' is at:
Akzeptierte Antwort
MathWorks Support Team
am 23 Jun. 2021
Bearbeitet: MathWorks Support Team
am 23 Jun. 2021
The following example shows how to pass additional arguments to the SET and GET command to access a property that requires additional indexing.
% axis types: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/bb208595(v=office.12) xlCategory = 1;
xlValue = 2;
% axis groups: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/bb208595(v=office.12) xlPrimary = 1;
xlSecondary = 2;
% open Excel using ActiveX
xlApp = actxserver('Excel.Application');
% set it to be visible
xlApp.Visible = true;
% inhibit "Do You Want to Save" dialog when Excel is closed.
xlApp.DisplayAlerts = false;
% Add a new workbook
xlWbook = invoke(xlApp.Workbooks,'add');
% Add a blank chart to the workbook
xlChart = invoke(xlWbook.Charts,'add');
% Go to the first sheet in the workbook
xlSheet = xlWbook.Sheets.Item('Sheet1');
% insert some data
xlSheet.Range('A1:B3').Value = { 1 20 ; 2 80; 4 100 };
% set the chart to use the data for the bar values
xlChart.SetSourceData( xlSheet.Range('A1:B3'));
% get the second data series
xlS2 = xlChart.SeriesCollection.Item(2);
xlS2.AxisGroup = 'xlSecondary'; % set it to display on the secondary axis.
% get current state of primary x axis
get(xlChart,'HasAxis',xlCategory,xlPrimary)
%ans = 1
% turn off primary x axis
set(xlChart,'HasAxis',xlCategory,xlPrimary,0)
%ans = NaN
% verify that it's off
get(xlChart,'HasAxis',xlCategory,xlPrimary)
% ans = 0
% turn it back on
set(xlChart,'HasAxis',xlCategory,xlPrimary,1)
% ans = NaN
% verify that it's on
get(xlChart,'HasAxis',xlCategory,xlPrimary)
% ans = 1
% display a y axis for secondary data
set(xlChart, 'HasAxis', xlValue, xlSecondary, 1)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!