生成EXCEL 的时候有时候会出错
Server Error in '/MTL' Application.
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Source Error:
Line 1408: {
Line 1409: object missing = System.Reflection.Missing.Value;
Line 1410: Excel.Application excel = new Excel.Application();//lauch excel application
Line 1411: Excel._Workbook xBk = null;
Line 1412: Excel._Worksheet xSt = null;
Source File: e:\SSL\MTL\ApplyMaterialTestEdit.aspx.cs Line: 1410
Stack Trace:
[COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).]
ApplyMaterialTestEdit.UpdateExcel(String strFileName) in e:\SSL\MTL\ApplyMaterialTestEdit.aspx.cs:1410
ApplyMaterialTestEdit.btnExcel_Click(Object sender, EventArgs e) in e:\SSL\MTL\ApplyMaterialTestEdit.aspx.cs:1405
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9796650
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +211
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
System.IO.IOException: The process cannot access the file 'E:\SSL\MTL\App_Data\Excel\WLm20220824142.xls' because it is being used by another process.
原因
根据你的报错提示:
System.IO.IOException: The process cannot access the file 'E:\SSL\MTL\App_Data\Excel\WLm20220824142.xls' because it is being used by another process.
很明显你的xlsx文件'E:\SSL\MTL\App_Data\Excel\WLm20220824142.xls'
被其他进程所打开了,所以导致你的程序无法进行读写而导致运行错误
解决方法
1、请查看下你的代码逻辑,是否有重复打开这个文件的逻辑
2、如果是的话,
在调用生成这个文件的时候前面加个flag判断,
如果该文件正在被调用的话就等待,或者看你的实际需要是否需要直接删除这个文件重新创建。
方法一
1、机器CPU负载高,进程启动时间长,不到120秒就无法执行CoRegisterClassObjects()。
2、COM 服务器没有注册正确的类 ID。
3、COM 服务器当前正在停止,并且 CoCreateInstance 和 COM 服务器停止部分之间存在竞争条件。
4、COM 服务器的启动方式存在安全问题(此页面似乎提示密码拼写错误或缺少“运行方式”COM 服务器的“作为批处理作业登录”权限,但无论如何我建议重新验证这一点特定配置的信息)
方法二
用这个解决方案解决了这个问题:右键单击 Component Services/Computers/DCOM Config/Microsoft Word97 - 2003 Document properties/General Tab
TLDR;,解决方法是从 File -> Options -> Save 禁用 AutoRecover, 然后丢弃所有自动恢复的文件。看起来它是自动恢复文件的数量,这是根本原因。
如有问题及时沟通
感觉是线程套间问题,这个组件不支持在这种模式下运行。需要在STL模式下运行。建议使用epplus库
你这个是有进程占用了,一个EXCEL文件,每次只能有一个进程在访问,如果再有访问的,就报错了,找到占用的进程关了就好
excel 限制访问了,1410 行代码在new的时候拒绝访问,应该看看哪些进程占用了excel 资源,将其释放
题面描述的问题和你后来恢复的问题:System.IO.IOException: The process cannot access the file 'E:\SSL\MTL\App_Data\Excel\WLm20220824142.xls' because it is being used by another process.不一致啊!不知道你究竟遇到什么问题?可以把错误代码贴出来看看能否解决。
朋友直接翻译不就好了……excel 限制访问了,代码在new的时候拒绝访问,朋友应该看看是哪里占用了excel 资源,关闭它即可
进程无法访问文件“E:\SSL\MTL\App_Data\Excel\WLm20220824142.xls”,因为它正在被其他进程使用。
建议尝试关闭当前excel文件后,再次执行此代码。
https://blog.csdn.net/weixin_43172531/article/details/112567038
最近使用python 在调用这个模块,出现过类似得错误,原因为a进程的实例,在b进程中调用, 如果不是同一进程,最好还是重新创建一个实例调用,
直接使用第三方库解决了 比这个还简单,nuget 'excel libary'
运行你的程序之前确保你要使用的excel文件已经关闭。
https://blog.csdn.net/weixin_43172531/article/details/112567038
https://blog.csdn.net/Joy__Zhao/article/details/81390555
网上的经验试一试吧
excel已经被另一个进程打开了,找到关闭
部分机器环境new Excel::Application执行失败的问题_御风@户外的博客-CSDN博客_excel.application对象失败 试试这篇博客