2

In Octave, this code:

excel.server    = actxserver('excel.application');
excel.workbooks = excel.server.workbooks;
excel.workbook  = excel.workbooks.add;
% excel.workbook.activate;
excel.workbook.SaveAs("a.xls");

results in a file being created at: C:/Users/kando/Documents/a.xls, whereas:

excel.server    = actxserver('excel.application');
excel.workbooks = excel.server.workbooks;
excel.workbook  = excel.workbooks.add;
% excel.workbook.activate;
excel.workbook.SaveAs('C:/Users/kando/Documents/a.xls');

results in the following error:

error: com_invoke: property/method invocation on the COM object failed with error `0x800a03ec' - lZ

I am thus unable to save anywhere when specifying an absolute or relative path.

(I am running the code from an entirely different directory, but the COM server only operates in the user's documents folder, it seems.)

How can I specify a path, (and how can I get more detailed error info when using COM server functions)?

kando
  • 441
  • 4
  • 16
  • 1
    What package is this? I don't recognise the commands. Also, windows typically uses backslash as the file separator, not slash. Try `C:\Users\kando\Documents\a.xls` instead, maybe it's as simple as that. Or better yet, use `fullfile`. – Tasos Papastylianou Feb 17 '21 at 23:57
  • Also, the error you're getting seems to be a specific excel error for when stuff is missing: https://stackoverflow.com/a/11016110/4183191 – Tasos Papastylianou Feb 18 '21 at 00:07
  • 1
    It was the backslashes. .. Kill me. You have no idea how much digging and reading I did. Please write that as an answer and I'll mark is so someone might find that error code and see that the answer can also be backslashes. – kando Feb 18 '21 at 14:26
  • hahahah, will do, glad to hear it helped xD – Tasos Papastylianou Feb 18 '21 at 16:10

1 Answers1

3

You are using a unix-style path separator (i.e. a forward slash: /).

Contrary to unix systems, formally the windows path separator is the backslash, i.e. \. Therefore, unless you are sure that the application you're passing this to is programmed flexibly so as to interpret both, you should probably be using a backslash specifically to ensure it's not treated as a 'malformed' path string when passed to windows applications.

In other words, you should be using 'C:\Users\kando\Documents\a.xls' instead of 'C:/Users/kando/Documents/a.xls' as your path string.

Better yet, you should use octave's fullfile facilities, which detects the correct file separator for you (via the filesep function), and builds an OS-compatible pathstring from the provided parts, i.e.

SaveFile = fullfile( 'C:', 'Users', 'kando', 'Documents', 'a.xls' );
excel.workbook.SaveAs( SaveFile );
Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57