I'm attempting to add sheets to an excel file.
It should be fairly straightforward; however, the following minimal working example below fails when attempting to skip optional arguments using empty braces. (Is this not correct? Source 1 Source 2)
clc
clear
% if COM error occurs, excel process remains open.
% use task manager to end process, else 'a.xlsx' file remains "in use".
srvr = actxserver('excel.application');
wbks = srvr.workbooks;
pth = fullfile(pwd, 'a.xlsx');
if ~exist(pth, 'file')
wbk = wbks.add;
wbk.activate;
wbk.saveAs( pth );
wbk.close;
end
wbk = wbks.open( pth, 0, false );
wbk.activate;
wshts = wbk.worksheets;
shts = wbk.sheets;
wsht = wshts.item(1);
wsht.activate;
sht = shts.item(1);
wsht.select(true);
sht.select(true);
%{
https://learn.microsoft.com/en-us/office/vba/api/excel.sheets.add
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheets.add
%}
shts.add(sht); % functions
shts.add(wsht); % functions
shts.add([],sht); % fails
shts.add([],wsht); % fails
shts.count
wbk.save;
srvr.quit;
Here is the error:
error: com_invoke: property/method invocation on the COM object failed with error `0x800a03ec' - Z
error: called from
trash at line 46 column 1
Note that the add
functions until skipping the first input. Are square brackets the wrong method to skip an input?
I have also posted this in Octave forum.
As per comments under the question,
this was a bug, which has been reported by OP and fixed in the development branch.