在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) li>
- 您的代码开始:
- 您创建一个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屋!