在 Delphi 7 中使用 TExcelWorkBook SaveAs 方法时出现 Ole 800A03EC 错误 [英] Ole 800A03EC error when using TExcelWorkBook SaveAs method in Delphi 7
问题描述
我正在尝试打开 excel 2003 工作簿并将其另存为其他内容,例如 excel 95.我使用以下代码:
I am trying to open excel 2003 workbook and save it as something else, for example excel 95. I use the following code:
XLSApp:=TExcelApplication.Create(Self);
XLSApp.Workbooks.Open(SomeFileName,NULL,false,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,defaultlcid);
XLSWB:=TExcelWorkbook.Create(XLSApp);
XLSWB.ConnectTo(XLSApp.Workbooks.Item[1]);
XLSWB.SaveCopyAs(ExtractFilePath(edTable.Text)+'temp.xls');
XLSWB.SaveAs(SomeOtherFileName,xlExcel7,EmptyParam,EmptyParam,False,False,xlNoChange,xlUserResolution,False,EmptyParam,EmptyParam,EmptyParam,DefaultLCID);
不幸的是,此代码在客户端计算机上显示Ole 800A03EC",而它在我的计算机上工作.请注意,我安装了 Office 2007,他安装了 Office 2003 SP3.
Unfortunately this code gives "Ole 800A03EC" on clients computer, while it works on mine. Note that I have Office 2007 installed, and he has Office 2003 SP3.
非常感谢任何帮助.
推荐答案
我在自动化 Excel 时遇到过一次此错误.当用户在编辑模式下有一个单元格并且您尝试自动化该实例时,就会发生这种情况.当您编辑单元格并且某些程序在后台摆弄时,Excel 不喜欢它.
I have seen this error once when automating Excel. It happened when the user had a cell in editmode and you tried to automate that instance. Excel doesn't like it when you are editing a cell and some program is fiddling around in the background.
这就是您的客户正在发生的事情(我认为):
So this is what's happening at your client (I think):
- 您的客户打开了 Excel,并且编辑单元格(选择一个单元格并按 F2)
- 您的代码开始:
- 您创建了一个 TExcelApplication 并访问了 Workbooks 属性.由于您的 Excel 应用程序尚未连接,它会调用 TOleServer.Connect(查看 GetDefaultInterface 的实现)
- 由于默认的 connectkind 是 ckRunningOrNew,TExcelApplication 连接到正在运行的实例.
- 因为客户端正在编辑单元格,所以您会在 Open 方法上遇到错误.
如何防止这种情况发生:将 TExcelApplication 的 ConnectKind 设置为 ckNewInstance,以便您始终在单独的 Excel 实例中工作.
How you can prevent this: Set ConnectKind of your TExcelApplication to ckNewInstance so you'll always work in a separate Excel instance.
这篇关于在 Delphi 7 中使用 TExcelWorkBook SaveAs 方法时出现 Ole 800A03EC 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!