bugGNU Octave - Bugs: bug #60098, [octave forge] (windows) Unable to...

 
 

bug #60098: [octave forge] (windows) Unable to skip optional arguments in COM method invocation

Submitter:  N Kando <itskando>
Submitted:  Mon 22 Feb 2021 02:37:10 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Fixed Assigned to:  lostbard
Originator Name:  itskando Open/Closed:  * Closed
Release:  * 6.1.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 28 Mar 2021 09:05:01 PM UTC, comment #10: 

windows 1.6.1 was released, containing this bug fix.

Closing report

John Donoghue <lostbard>
Group Member
Tue 23 Feb 2021 04:41:18 PM UTC, comment #9: 

oh awesome! thank you for the rapid support and transparent communication : j

N Kando <itskando>
Tue 23 Feb 2021 10:11:57 AM UTC, comment #8: 

Re comment #5: That change was made in the windows package.
New package releases are independent of Octave releases.
When a new version of the "windows" package is released on Octave Forge, you could update in Octave with the command `pkg update windows`.

Markus Mützel <mmuetzel>
Group administrator
Mon 22 Feb 2021 08:59:33 PM UTC, comment #7: 

The code was probably antiquated when I posted it.

Here's my most up to date:


% if COM error, excel process remains open.
% use task manager to end process.

if exist('wbks', 'var')

if wbks.count > 0
  wbks.close;
end

release(srvr);

end

clc
clear

% setup
pkg('load', 'windows') % COM objects (for interfacing with office VBA)

srvr = actxserver('excel.application');
wbks = srvr.workbooks;

pth  = fullfile(pwd, 'a.xlsx');

if exist(pth, 'file')

  delete( pth );

%  wbk = wbks.open( pth, 0, false );
%  wbk.activate;

end

wbk = wbks.add;
wbk.activate;
wbk.saveAs( pth );


wshts     = wbk.worksheets;
wsht{1,1} = wshts.item(1);
wsht{1,1}.activate;
wsht{1,1}.select(true);

shts     = wbk.sheets;
sht{1,1} = shts.item(1);
sht{1,1}.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
https://www.mathworks.com/help/matlab/matlab_external/insert-a-spreadsheet-after-sheet-1.html
%}

wshts0.label = { 'Apple'
                 'Banana'
                 'Clementine'
               };

for i0 = 2 : size( wshts0.label, 1)

  switch 0

  case 0; shts.add(                   sht{1,1} ); % functions
  case 1; shts.add(                  wsht{1,1} ); % functions

  case 2; shts.add(             '[]', sht{1,1} ); % fails
  case 3; shts.add(              [] , sht{1,1} ); % fails
  case 4; com_invoke(shts,'add','[]','sht{1,1}'); % fails

  end

end


for i0 = 1 : size( wshts0.label, 1)
sht{i0,1}      = shts.item(i0);
sht{i0,1}.name = wshts0.label{i0,1};
end

wbk.save;
wbks.close;
release(srvr)


N Kando <itskando>
Mon 22 Feb 2021 08:42:49 PM UTC, comment #6: 

FTR, out of curiosity I tried the code in Matlab r2020b:

>> 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
Check for missing argument or incorrect argument data type in call to function 'add'.

>> wbk = wbks.open( pth, 0, false );
Error using open
Too many input arguments.


... so the code itself doesn't seem completely right.
(Windows 10 & Office 2016, if it matters)

Philip Nienhuis <philipnienhuis>
Group Member
Mon 22 Feb 2021 07:48:44 PM UTC, comment #5: 

comment #4:

> it will appear in the next release


Awesome - Are octave releases common, or should I move onto a dev train?

N Kando <itskando>
Mon 22 Feb 2021 06:01:55 PM UTC, comment #4: 

I pushed up a change to the repo

https://sourceforge.net/p/octave/windows/ci/ac7a22f8ebd0fbcd709c90cb7ef19dd98fd28332/

So it will appear in the next release

John Donoghue <lostbard>
Group Member
Mon 22 Feb 2021 04:10:07 PM UTC, comment #3: 

That would be 'currently does not support it.'

John Donoghue <lostbard>
Group Member
Mon 22 Feb 2021 04:09:05 PM UTC, comment #2: 

Thanks for the report.

To the question: 'Are square brackets the wrong method to skip an input?' The answer is that the octave implementation does currently doesnt support it.

I'll take a look and adding it in.


John Donoghue <lostbard>
Group Member
Mon 22 Feb 2021 03:50:07 PM UTC, comment #1: 

CC'ing John D as the package maintainer.

Markus Mützel <mmuetzel>
Group administrator
Mon 22 Feb 2021 02:37:10 PM UTC, original submission:  

Using empty brackets to skip optional arguments always fails. User on octave forums has possibly identified source of problem and also determined solution.

Issue, possible source of problem, and possible solution described here:

https://octave.discourse.group/t/package-windows-unable-to-skip-optional-arguments-in-com-objects-possible-bug/798

.
.
.

The following minimal working example below fails when attempting to skip optional arguments using empty braces.

Expected usage syntax described here:

https://www.mathworks.com/help/matlab/matlab_external/using-methods.html


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?

.
.
.

Suggestion from other user:

MSDN: [Office Automation Using Visual C++ (microsoft.com)](https://support.microsoft.com/en-us/topic/office-automation-using-visual-c-67da40c2-7671-f700-474d-36ac522d76f2)

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.

N Kando <itskando>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lostbard (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by mmuetzel
  • -email is unavailable- added by itskando (Submitted the item)
  • -email is unavailable- added by itskando
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-03-28 lostbard StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-02-22 lostbard StatusConfirmed Ready For Test
    2021-02-22 lostbard Item GroupUnexpected Error or Warning Feature Request
        Assigned toNone lostbard
    2021-02-22 mmuetzel StatusNone Confirmed
        SummaryPackage: windows: Unable to skip optional arguments in COM objects [octave forge] (windows) Unable to skip optional arguments in COM method invocation
        Carbon-Copy- Added lostbard
    2021-02-22 itskando Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code