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)?

4
  • 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. Commented Feb 17, 2021 at 23:57
  • Also, the error you're getting seems to be a specific excel error for when stuff is missing: stackoverflow.com/a/11016110/4183191 Commented Feb 18, 2021 at 0: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. Commented Feb 18, 2021 at 14:26
  • hahahah, will do, glad to hear it helped xD Commented Feb 18, 2021 at 16:10

1 Answer 1

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 );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.