Ole 800A03EC error when using TExcelWorkBook SaveAs method in Delphi 7

爷,独闯天下 提交于 2019-11-30 14:52:43

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

  • Your client has Excel open and is editing a cell (select a cell and press F2)
  • Your code starts:
    • You create a TExcelApplication and accesses the Workbooks property. Since your Excel application is not yet connected it calls TOleServer.Connect (look at the implementation of GetDefaultInterface)
    • Since the default connectkind is ckRunningOrNew, TExcelApplication connects to the running instance.
    • Because the client is editing a cell you get an error on the Open method.

How you can prevent this: Set ConnectKind of your TExcelApplication to ckNewInstance so you'll always work in a separate Excel instance.

MA refugee

800A03EC also occurs when one (like, me) does a dumb thing like trying to load into an Excel cell that doesn't exist, like:

excel.Cells[rowIndex, ri] = x;
where ri is 0.

NOTE BENE: The col index starts at 1, not 0.

OLE 800A03EC usually has to do with invalid characters in your Excel file. Are you using the same data as your client? Is there a difference in Regional Settings? Etc. etc. there could be number of errors for this, but most likely (as a quick google told me) it is a regional setting.

Adren

In my case ( xlExcel8 format ):

Instead of:

theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName, myExcel.XlFileFormat.xlExcel8);

I used:

theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName);

or

theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName, myExcel.XlFileFormat.xlExcel7);

Both work well... And yes, I know this is a stupid solution, but it's working!

I'm getting that error when trying to store too much data to the WorkSheet (through Delphi)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!