ErrorMessage in Excel

怎甘沉沦 提交于 2019-12-12 12:03:48

问题


i got a urgent problem with the following error, while setting the DisplayAlerts-property of the Excel ApplicationClass to false.

var excel = new Excel.Application();
excel.DisplayAlerts = false;

I get the following error message in the logs:

System.Runtime.InteropServices.COMException (0x800AC472): Exception from HRESULT: 0x800AC472
     at Microsoft.Office.Interop.Excel.ApplicationClass.set_DisplayAlerts(Boolean RHS)
     at Service.Dispose()

The following MessageBox is shown


(source: xlam.ch)

Any ideas on this case?

Regards MacX


回答1:


I think you should call DisplayAlerts on the instance of Excel.Application you're working with. Something like this:

var excel = new Excel.Application();
excel.DisplayAlerts = false;



回答2:


You'll have to catch that error and re-submit whatever you were inserting into a cell on excel. This is an annoying bug and I have not been able to implement and elegant solution for.

Someone can correct me if I am wrong but I cannot find a way to determine if Excel is in a "suspended" state or not besides catching this exception. It's like an unavoidable race condition where you don't know the result until you know the result. I searched for a way to solve this before giving up and implemented an ugly error checking solution.

Sorry, I hope someone has a better solution for this than me.



来源:https://stackoverflow.com/questions/5246288/errormessage-in-excel

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