excel ole“添加工作簿类方法失败”错误
我正在尝试通过 ole 打开并刷新 Excel 2003 电子表格。但是,我收到错误“工作簿类的添加方法失败”,没有进一步的信息。
该代码可以在单元测试中运行,并且可以在 3 个服务器上运行,但在我们的 Web 服务器上失败并出现错误。它是从在本地系统帐户下运行的服务应用程序运行的。
所有服务器上都安装了相同版本的 excel (2003 sp3)。有问题的文件全部存在并且位于预期位置。
电子表格中没有宏,但有数据库查询。电子表格都可以打开。
调用代码是
if VarIsEmpty(XLApp) then
begin
XLApp := CreateOleObject('Excel.Application');
try
XLApp.DisplayAlerts:= wdAlertsNone;
except
...
end;
XLApp.AutomationSecurity:= msoAutomationSecurityForceDisable;
end;
fullFileName:= ExpandReportFileName( partialFilename);
if not FileExists(fullFileName) then
raise Exception.Create('File not found: ' + fullFileName);
XLAPP.Workbooks.Add(fullFileName); << fail here
关于我还可以尝试什么的任何想法?
I am trying to open and refresh an excel 2003 spreadsheet via ole. However I am getting the error "Add method of Workbooks class failed" with no further information.
The code works in unit tests, and works on 3 servers but fails with the error on our web server. It is being run from a service app running under the Local System Account.
The same version of excel is installed on all servers (2003 sp3). The file(s) in question all exist and are at the expected location.
There are no macros in the spreadsheets, but there are database queries. The spreadsheets can all be opened.
The calling code is
if VarIsEmpty(XLApp) then
begin
XLApp := CreateOleObject('Excel.Application');
try
XLApp.DisplayAlerts:= wdAlertsNone;
except
...
end;
XLApp.AutomationSecurity:= msoAutomationSecurityForceDisable;
end;
fullFileName:= ExpandReportFileName( partialFilename);
if not FileExists(fullFileName) then
raise Exception.Create('File not found: ' + fullFileName);
XLAPP.Workbooks.Add(fullFileName); << fail here
Any ideas on what else I can try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我收到了同样的错误,因为
我将该行更改为“
现在它正在工作”。您可以先尝试获取工作簿,然后尝试调用其方法。
I had been getting the same error for
I changed that line to
Now it is working. You might try to get a Workbook first then try to call its methods.
不支持在服务中自动化 Office 应用程序。
虽然这是可能的,但是非常困难,你会遇到很多问题,比如这个。它也会非常慢。
您应该寻找一个可以操作 Excel 文件的 Delphi 组件。
根据您尝试执行的操作,您也许可以改用 OLE DB。
Automating Office applications in a service is not supported.
While it is possible, it's very difficult, and you'll run into many problems, such as this one. It'll also be very slow.
You should look for a Delphi component that manipulates Excel files.
Depending on what you're trying to do, you might be able to use OLE DB instead.
Workbooks.Open
可能是您正在寻找的方法Add
创建一个新的空工作簿。如果您提供文件名,则该文件将用作新文件的模板 - 请参阅 此处打开
只是按照您的预期打开文件 - 请参阅此处Workbooks.Open
might be the method you're looking forAdd
creates a new empty workbook. If you supply a filename, that file is used as a template for the new file - see hereOpen
just opens the file as you would expect - see here当我碰巧在 Windows 资源管理器窗口中选择了 Excel 电子表格文件(未打开,只是选择)时,我遇到了此错误。当我取消选择该文件时,我没有收到错误消息。
I ran into this error when I happened to have the Excel spreadsheet file selected in a Windows Explorer window, not open, just selected. When I deselect the file, I do not get the error.