C# 生成Excel 报错COMException(0x800A03EC)

报错如下图:C# 生成Excel 报错COMException(0x800A03EC)

解决方法参考链接:

     http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4d6c383a-94eb-4898-9d22-aa4bb69be25b/

    http://s.yanghao.org/program/viewdetail.php?i=104274

    http://stackoverflow.com/questions/4408336/system-runtime-interopservices-comexception-0x800a03ec

   http://forums.asp.net/t/1585488.aspx/1

两种主要的说法:

1.

The solution for this appalling BUG in Microsoft IIS & Excel is terrific:
Create directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or "C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)
Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user 
"IIS AppPool\DefaultAppPool")

 

2. 

一种是配置好了相应的Excel的DCOM权限

2:在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务"  
3:依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置"  
4:在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击右键,然后点击"属性",弹出"Microsoft Excel 应用程序属性"对话框  
5:点击"标识"标签,选择"交互式用户"  
6:点击"安全"标签,在"启动和激活权限"上点击"自定义",然后点击对应的"编辑"按钮,在弹出的"安全性"对话框中填加一个"NETWORK SERVICE"用户(注意要选择本计算机名),并给它赋予"本地启动"和"本地激活"权限.  
7:依然是"安全"标签,在"访问权限"上点击"自定义",然后点击"编辑",在弹出的"安全性"对话框中也填加一个"NETWORK SERVICE"用户,然后赋予"本地访问"权限.  
这样,我们便配置好了相应的Excel的DCOM权限.
 
在上面的链接中也有人这样说,不过是英文写的:
I tried that and the error did not go away. However, after using the management console on the server: Start, Run, then type mmc comexp.msc /32 for the 32-bit version.

We are using impersonation in our ASP.NET application, and using a domain user account.

Then selected Component Services, Computers, my computer, DCOM Config, Microsoft Excel Application. Right click, select Properties. On the Security tab, select Customize for Launch and Acitvation Permissions, and add the domain user. Also added the user on the Identity tab, select "This User", and type the user id and password.

After this, and added the aforementioned folder path, Excel worked fine, opening files.

 

你可能感兴趣的:(exception)