Octave:无法通过 COM 功能保存 Excel 文件(COM 错误 0x800a03ec) [英] Octave: Unable to save excel file via COM function (COM error 0x800a03ec)

查看:105
本文介绍了Octave:无法通过 COM 功能保存 Excel 文件(COM 错误 0x800a03ec)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Octave 中,此代码:

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");

导致在以下位置创建文件:C:/Users/kando/Documents/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');

导致以下错误:

error: com_invoke: 对 COM 对象的属性/方法调用失败,错误为 `0x800a03ec' - lZ

因此,在指定绝对或相对路径时,我无法在任何地方保存.

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

(我从一个完全不同的目录运行代码,但 COM 服务器似乎只在用户的文档文件夹中运行.)

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

如何指定路径(以及如何在使用 COM 服务器功能时获得更详细的错误信息)?

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

推荐答案

您正在使用 unix 样式的路径分隔符(即正斜杠:/).

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

与 unix 系统相反,正式的 Windows 路径分隔符是反斜杠,即 \.因此,除非您确定将其传递给的应用程序经过灵活编程以解释两者,否则您可能应该专门使用反斜杠以确保在传递给 Windows 应用程序时不会将其视为格式错误"的路径字符串.

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.

换句话说,你应该使用 'C:\Users\kando\Documents\a.xls' 而不是 'C:/Users/kando/Documents/a.xls' 作为您的路径字符串.

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.

更好的是,您应该使用八度的 fullfile 工具,它为您检测正确的文件分隔符(通过 filesep 函数),并从提供的部分,即

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

这篇关于Octave:无法通过 COM 功能保存 Excel 文件(COM 错误 0x800a03ec)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆