Package: windows: Unable to skip optional arguments in COM objects (possible bug)

I’m attempting to use octave 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://docs.microsoft.com/en-us/office/vba/api/excel.sheets.add
https://docs.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.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?

Original source.

Also posted in stackexchange, but we’re stumped there too.

MSDN: Office Automation Using Visual C++ (microsoft.com)

If I read point 6 correctly, optional arguments that are skipped should be passed with the following value in C++:

      // VARIANT used in place of optional-parameters.
      VARIANT varOpt;
      varOpt.vt = VT_ERROR;
      varOpt.scode = DISP_E_PARAMNOTFOUND;

The COM interface in the windows package seems to use the following instead:

  else if (ov.is_real_matrix () && ov.OV_ISEMPTY ())
  {
    var->vt = VT_EMPTY;
  }

That might be the reason for this not working.

Could you please open a bug report on savannah?
GNU Octave - Bugs: Browse Items [Savannah]

1 Like

https://savannah.gnu.org/bugs/?60098