.net System.Runtime.InteropServices.COMException (0x800A03EC)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4408336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:01:23  来源:igfitidea点击:

System.Runtime.InteropServices.COMException (0x800A03EC)

.netiiscomexcel-interop

提问by Sameer S

Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs()method is working fine on Windows server 2003 and also on XP but not on Windows server 2008. I copied it as it is gave all Dll's and permissions

Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs()方法在 Windows server 2003 和 XP 上运行良好,但在 Windows server 2008 上却没有。我复制了它,因为它被赋予了所有的 Dll 和权限

I have also tried all the solutions given on the net, such as Culture settings and DCOM permission.

我也尝试了网络上给出的所有解决方案,例如文化设置和 DCOM 权限。

Getting following error:

得到以下错误:

System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC

System.Runtime.InteropServices.COMException (0x800A03EC):来自 HRESULT 的异常:0x800A03EC

at

Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)

Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(对象文件名、对象文件格式、对象密码、对象WriteResPassword、对象ReadOnlyRecommended、对象CreateBackup、XlSaveAsAccessMode AccessMode、对象冲突解决、对象AddToMru、对象TextCodepage、对象TextVisualLayout、对象本地)

Please help ..!

请帮忙 ..!

回答by Sameer S

Found Answer.......!!!!!!!

找到答案了......!!!!!!!!!

Officially Microsoft Office 2003 Interop is not supported on Windows server 2008 by Microsoft.

Microsoft 在 Windows Server 2008 上正式不支持 Microsoft Office 2003 Interop。

But after a lot of permutations & combinations with the code and search, we came across one solution which works for our scenario.

但是在对代码和搜索进行了大量排列组合之后,我们发现了一种适用于我们场景的解决方案。

The solution is to plug the difference between the way Windows 2003 and 2008 maintains its folder structure, because Office Interop depends on the desktop folder for file open/save intermediately. The 2003 system houses the desktop folder under systemprofile which is absent in 2008.

解决办法是堵住Windows 2003和2008维护文件夹结构方式的不同,因为Office Interop中间文件打开/保存依赖于桌面文件夹。2003 系统将桌面文件夹放在 systemprofile 下,而 2008 则没有。

So when we create this folder on 2008 under the respective hierarchy as indicated below; the office Interop is able to save the file as required. This Desktop folder is required to be created under

因此,当我们在 2008 年在各自的层次结构下创建此文件夹时,如下所示;Office Interop 可以根据需要保存文件。这个桌面文件夹需要在下面创建

C:\Windows\System32\config\systemprofile

C:\Windows\System32\config\systemprofile

AND

C:\Windows\SysWOW64\config\systemprofile

C:\Windows\SysWOW64\config\systemprofile

This worked for me...

这对我有用...

Also do check if .NET 1.1 is installed because its needed by Interop and ot preinstalled by Windows Server 2008

还要检查是否安装了 .NET 1.1,因为 Interop 需要它并且 Windows Server 2008 预装了它

Or you can also Use SaveCopyas() method ist just take onargument as filename string)

或者你也可以使用 SaveCopyas() 方法只是将 onargument 作为文件名字符串)

Thanks Guys..!

谢谢你们..!

回答by Pratik Gaikwad

Try this as it worked for me...

试试这个,因为它对我有用......

  1. Go to "Start" -> "Run" and enter "dcomcnfg"
  2. This will bring up the component services window, expand out "Console Root" -> "Computers" -> "DCOM Config"
  3. Find "Microsoft Excel Application" in the list of components.
  4. Right click on the entry and select "Properties"
  5. Go to the "Identity" tab on the properties dialog.
  6. Select "The interactive user."
  1. 转到“开始”->“运行”并输入“dcomcnfg”
  2. 这将打开组件服务窗口,展开“Console Root”->“Computers”->“DCOM Config”
  3. 在组件列表中找到“Microsoft Excel 应用程序”。
  4. 右键单击该条目并选择“属性”
  5. 转到属性对话框上的“身份”选项卡。
  6. 选择“交互式用户”。

courtesy of Last paragraph mentioned in here

礼貌在这里提到最后一段

回答by Eamon Nerbonne

Some googling reveals that potentially you've got a corrupt file:

一些谷歌搜索显示您可能有一个损坏的文件:

http://bitterolives.blogspot.com/2009/03/excel-interop-comexception-hresult.html

http://bitterolives.blogspot.com/2009/03/excel-interop-comexception-hresult.html

and that you can tell excel to open it anyway with the CorruptLoad parameter, with something like...

并且您可以告诉 excel 无论如何使用 CorruptLoad 参数打开它,例如...

Workbook workbook = excelApplicationObject.Workbooks.Open(path, CorruptLoad: true);

回答by GreeenMachin

I was seeing this same error when trying to save an excel file. The code worked fine when I was using MS Office 2003, but after upgrading to MS Office 2007 I started seeing this. It would happen anytime I tried to save an Excel file to a server or remote fie share.

我在尝试保存 excel 文件时看到了同样的错误。当我使用 MS Office 2003 时,代码运行良好,但在升级到 MS Office 2007 后,我开始看到这一点。任何时候我尝试将 Excel 文件保存到服务器或远程文件共享时都会发生这种情况。

My solution, though rudimentary, worked well. I just had the program save the file locally, like to the user's C:\ drive. Then use the "System.IO.File.Copy(File, Destination, Overwrite)" method to move the file to the server. Then you can delete the file on the C:\ drive.

我的解决方案虽然很初级,但效果很好。我只是让程序将文件保存在本地,比如保存到用户的 C:\ 驱动器。然后使用“System.IO.File.Copy(File, Destination, Overwrite)”方法将文件移动到服务器。然后您可以删除 C:\ 驱动器上的文件。

Works great, and simple. But admittedly not the most elegant approach.

效果很好,而且很简单。但不可否认,这不是最优雅的方法。

Hope this helps! I was having a ton of trouble finding any solutions on the web till this idea popped into my head.

希望这可以帮助!我在网上找到任何解决方案时遇到了很多麻烦,直到这个想法突然出现在我的脑海中。

回答by daniele3004

It 'a permission problem when IIS is running I had this problem and I solved it in this way

这是IIS运行时的权限问题我遇到了这个问题,我以这种方式解决了它

I went on folders

我去了文件夹

C:\Windows\ System32\config\SystemProfile

C:\Windows\ System32\config\SystemProfile

and

C:\Windows\SysWOW64\config\SystemProfile

C:\Windows\SysWOW64\config\SystemProfile

are protected system folders, they usually have the lock.

是受保护的系统文件夹,它们通常有锁。

Right-click-> Card security-> Click on Edit-> Add untente "Autenticadet User" and assign permissions.

右键->卡安全->点击编辑->添加untente“Autenticadet用户”并分配权限。

At this point everything is solved, if you still have problems try to give all permissions to "Everyone"

至此一切都解决了,如果还有问题尝试给“所有人”所有权限

回答by Ugur Catak

In my case, the problem was styling header as "Header 1" but that style was not exist in the Word that I get the error because it was not an Office in English Language.

就我而言,问题是将标题样式设置为“标题 1”,但该样式在 Word 中不存在,我收到错误消息,因为它不是英语的 Office。

回答by trailmax

For all of those, who still experiencing this problem, I just spent 2 days tracking down the bloody thing. I was getting the same error when there was no rows in dataset. Seems obvious, but error message is very obscure, hence 2 days.

对于所有仍然遇到此问题的人,我只花了 2 天的时间来追踪该血腥的事情。当数据集中没有行时,我遇到了同样的错误。看起来很明显,但错误信息非常模糊,因此需要 2 天。