Windows 7 .net Excel .SaveAs() 来自 HRESULT 的错误异常:0x800A03EC

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1981395/
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 13:43:09  来源:igfitidea点击:

Windows 7 .net Excel .SaveAs() Error Exception from HRESULT: 0x800A03EC

.netexcelwindows-7

提问by Jeff Keslinke

Background:
I toasted my old hard drive at work and am getting a new one. With that I'll have to rebuild my machine. My manager has Windows 7 installed on him loaner laptop that I've been using while my machine is out of commision. But I've run into a problem.

背景:
我在工作时为我的旧硬盘敬酒,现在正在换一个新硬盘。有了这个,我将不得不重建我的机器。我的经理在他借用的笔记本电脑上安装了 Windows 7,我在我的机器无法使用时一直在使用它。但我遇到了一个问题。

We have a fair number of apps that make use of the Microsoft.Office.Interop.Excel reference. I've gotten past a few errors so far but the one I've been stuck on for the last few days (my machine actually suffered the hard drive failure after the first rebuild) and have been unnable to find a fix. I have searched for this error but can't find anyone having this problem on Windows 7, although I have tried other fixes for Windows Server 2008 to no avail.

我们有相当多的应用程序使用 Microsoft.Office.Interop.Excel 参考。到目前为止,我已经克服了一些错误,但是最近几天我一直在坚持这个错误(我的机器在第一次重建后实际上遇到了硬盘故障)并且无法找到修复程序。我已经搜索了这个错误,但在 Windows 7 上找不到任何有这个问题的人,尽管我尝试了 Windows Server 2008 的其他修复程序无济于事。

If I can't fix this problem, I will not be able to use Windows 7 and would like to know that before I rebuild a machine only to have to wipe it and start again (for the third time).

如果我不能解决这个问题,我将无法使用 Windows 7 并且想知道在我重建机器之前只需要擦除它并重新启动(第三次)。

Problem:
OS: Windows 7 Enterprise
Error Message: Exception from HRESULT: 0x800A03EC
Code:

问题:
操作系统:Windows 7 Enterprise
错误消息:来自 HRESULT 的异常:0x800A03EC
代码:

Private m_xls As Microsoft.Office.Interop.Excel.Application
Private m_wkbk As Microsoft.Office.Interop.Excel.Workbook
Private m_wksht As Microsoft.Office.Interop.Excel.Worksheet
m_xls = New Application
m_xls.Visible = False : m_xls.DisplayAlerts = False
m_wkbk = m_xls.Workbooks.Open(Me.FilePath)
m_wksht = CType(m_wkbk.ActiveSheet, Worksheet)
'...Write some data...'
m_wkbk.SaveAs(Me.FilePath, XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, False, False, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)

The error occurs on the final line.

错误发生在最后一行。

What I've tried so far:

到目前为止我尝试过的:

  1. Changing the AppPool to use the NetworkService account (it was 'ApplicationPoolIdentity' which I couldn't find in the user list in security settings). Then giving the NetworkService account full access to the appropriate folder.
  2. Giving NetworkService access to all 'Microsoft Excel Application' settings in DCOMCNFG
  3. Running this command "appcmd set config -section:asp -enableParentPaths:true" because it's the only other thing I could find
  4. Using the .SaveCopyAs() which worked but caused different errors
  1. 更改 AppPool 以使用 NetworkService 帐户(我在安全设置的用户列表中找不到它是“ApplicationPoolIdentity”)。然后授予 NetworkService 帐户对相应文件夹的完全访问权限。
  2. 授予 NetworkService 访问 DCOMCNFG 中所有“Microsoft Excel 应用程序”设置的权限
  3. 运行此命令“appcmd set config -section:asp -enableParentPaths:true”,因为这是我唯一能找到的其他东西
  4. 使用有效但导致不同错误的 .SaveCopyAs()

I just wanted to see if anyone else has run into this or not since Windows 7 is new. I can go with Server 2008 but I would like to have some solid reasoning behind it before I tell my manager it won't work.

我只是想看看是否有其他人遇到过这个问题,因为 Windows 7 是新的。我可以使用 Server 2008,但在告诉我的经理它不起作用之前,我想在它背后有一些可靠的推理。

Thank you, Jeff

谢谢你,杰夫

回答by Jeff Keslinke

Note: This needs to be condensed a bit as it's a compilation of all the fixes I've been making on our internal wiki but I'm not sure what subset of changes made it work so I'll include it all.

注意:这需要稍微压缩一下,因为它是我在我们内部 wiki 上所做的所有修复的汇编,但我不确定哪些更改使它起作用,因此我将全部包含在内。

Solution:

解决方案:

The following changes may be a superset of how to address this problem.

以下更改可能是如何解决此问题的超集。

-Run DCOMCNFG.exe and navigate to 'Component Services>Computers>My Computer'.
-Right click 'My Computer' and click 'Properties'.
-Open the 'COM Security' tab. Add your account for everyone of the buttons listed ('Edit Limits...' and 'Edit Default...' buttons under 'Access Permission' & 'Launch and Activate Permissions'). Give your account all access options. Click 'Apply' then 'OK'.
-While still in DCOMCNFG expand the 'My Computer' link and open the 'DCOM Config' folder.
-Right click on 'Microsoft Excel Application' and select 'Properties'.
-Under the 'Security' tab choose the 'Customize' option for 'Launch and Activation Permissions' and 'Configuration Permissions'. For both click the 'Edit...' button. Give your account access to everything.
-While still in the 'Properties' for 'Microsoft Excel Application' go to the 'Identity' tab.
-Select the 'The Interactive User' option.
-Click 'Apply' then 'OK'.
-Restart your computer.

- 运行 DCOMCNFG.exe 并导航到“组件服务>计算机>我的电脑”。
- 右键单击​​“我的电脑”,然后单击“属性”。
- 打开“COM 安全”选项卡。为列出的每个按钮添加您的帐户(“访问权限”和“启动和激活权限”下的“编辑限制...”和“编辑默认...”按钮)。为您的帐户提供所有访问选项。单击“应用”,然后单击“确定”。
- 仍在 DCOMCNFG 中时,展开“我的电脑”链接并打开“DCOM 配置”文件夹。
- 右键单击​​“Microsoft Excel 应用程序”并选择“属性”。
- 在“安全”选项卡下,为“启动和激活权限”选择“自定义”选项和“ 配置权限”。对于两者,请单击“编辑...”按钮。授予您的帐户访问所有内容的权限。
- 在“Microsoft Excel 应用程序”的“属性”中,转到“身份”选项卡。
- 选择“交互式用户”选项。
- 单击“应用”,然后单击“确定”。
-重启你的电脑。

-Try the below DCOMCNFG& ApplicationPoolIdentity change.

- 尝试以下DCOMCNFG和 ApplicationPoolIdentity 更改。

-Run command prompt as Administrator.
-Navigate to c:\Windows\System32\inetsrv> and run 'appcmd set config -section:asp -enableParentPaths:true'

- 以管理员身份运行命令提示符。
-导航到 c:\Windows\System32\inetsrv> 并运行“appcmd set config -section:asp -enableParentPaths:true”

Alternately you could use .SaveCopyAs() although this may still not address the problem and will require code changes.

或者,您可以使用 .SaveCopyAs() 虽然这可能仍然无法解决问题并且需要更改代码。

DCOMCNFG For windows 7:

DCOMCNFG 对于 Windows 7:

This error happens on 'Excel app = New Application();' calls

此错误发生在“Excel app = New Application();”上 电话

This link details how to fix the problem for XP/Server 2003 but can be adapted to Windows 7: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

此链接详细说明了如何解决 XP/Server 2003 的问题,但也适用于 Windows 7:http: //blog.crowe.co.nz/archive/2006/03/02/589.aspx

I do not have/could not find an 'ASPNET' account. You have to check the application pool to find out what the app is running as.
To do that go into 'Computer Management>Services and Applications>Internet Information Services>Application Pools'
Right click on the appropriate AppPool and choose 'Advanced Settings'. Under 'Process Model>Identity' you can find the account it is running under. Mine was 'ApplicationPoolIdentity' which I also couldn't find so I changed it to 'Network Service' like Windows Server 2003.
Once this is set run DCOMCNFG.exe. Navigate to 'Component Services>Computers>My Computer>DCOM Config'.
Find and right-click on 'Microsoft Excel Application' and select 'Properties'. Choose the 'Security' tab. Under 'Launch and Activation Permissions' choose 'Customize' and click 'Edit'.
Then click the 'Add...' button.
Type the name of the the appropriate account, in this case 'Network Service' and click 'Check Names'. Then click 'OK'.
Back on the 'Launch and Activation Permissions' page highlight the 'Network Service' account and check the 'Local Launch' and 'Local Activation' check boxes. Then click 'OK'.

我没有/找不到“ASPNET”帐户。您必须检查应用程序池以了解应用程序的运行方式。
为此,请进入“计算机管理>服务和应用程序>Internet 信息服务>应用程序池”
右键单击相应的 AppPool 并选择“高级设置”。在“流程模型>身份”下,您可以找到它正在运行的帐户。我的是“ApplicationPoolIdentity”,我也找不到,所以我将其更改为“网络服务”,如 Windows Server 2003。
设置后运行 DCOMCNFG.exe。导航到“组件服务>计算机>我的电脑>DCOM 配置”。
找到并右键单击“Microsoft Excel 应用程序”并选择“属性”。选择“安全”选项卡。在“启动和激活权限”下选择“自定义”并单击“编辑”。
然后单击“添加...”按钮。
键入适当帐户的名称,在本例中为“网络服务”,然后单击“检查名称”。然后单击“确定”。
返回“启动和激活权限”页面,突出显示“网络服务”帐户并选中“本地启动”和“本地激活”复选框。然后单击“确定”。

回答by Rick Mogstad

When I was getting this error, I think I started using .SaveCopyAs instead of SaveAs. I'm not sure what other errors this is causing you, if you could elaborate there perhaps something could be figured out for that situation.

当我收到此错误时,我想我开始使用 .SaveCopyAs 而不是 SaveAs。我不确定这会导致您出现哪些其他错误,如果您能在那里详细说明,也许可以解决这种情况。

Also, one thing that you are doing is most likely causing excel.exe to remain in memory after processing a file. Here is an article that shows the proper way to use and release COM interop objects (http://support.microsoft.com/kb/317109). It is a pain, but it worked for me in allowing those resources to be released before the app closed.

此外,您正在做的一件事很可能导致 excel.exe 在处理文件后保留在内存中。这是一篇文章,展示了使用和释放 COM 互操作对象的正确方法 ( http://support.microsoft.com/kb/317109)。这很痛苦,但它对我有用,允许在应用程序关闭之前释放这些资源。

回答by ShdNx

Make sure you're running the program (and EXCEL.EXE) as administrator, and the directory you're saving to doesn't have "read-only" attribute on.

确保您以管理员身份运行程序(和 EXCEL.EXE),并且您保存的目录没有“只读”属性。

Also, try passing the full file path instead of just the file name.

此外,尝试传递完整的文件路径,而不仅仅是文件名。

You could also try passing System.Reflection.Missing.Value instead of omitting the optional parameters.

您也可以尝试传递 System.Reflection.Missing.Value 而不是省略可选参数。

Can't think of anything else right now. Hope this helps.

暂时想不出别的了。希望这可以帮助。

ShdNx

神经网络

回答by user1437891

The answer above by Jeff Keslinke ended up working for me. You also need to look at the application pool that your App is using and make sure the identity is correct and has full access and privileges.

Jeff Keslinke 上面的答案最终对我来说有效。您还需要查看您的应用程序正在使用的应用程序池,并确保身份正确并具有完全访问权限和特权。

回答by Hyman Liu Shurui

I got the same issue and found application crash errors with Exception code: 0xc0000005 in windows events. Search web and find the following solution at the linkExcel 2010 Crash, Exception code: 0xc0000005Rename the file extension of the opened file from xlsx to zip. The solution works for my case.

我遇到了同样的问题,并在 Windows 事件中发现应用程序崩溃错误,异常代码为:0xc0000005。搜索网页并在链接Excel 2010 Crash, Exception code: 0xc0000005 中找到以下解决方案将打开的文件的文件扩展名从 xlsx 重命名为 zip。该解决方案适用于我的情况。

回答by Shashank Jangiti

Try turning on ISS . The details are mentioned here for windows 7

尝试打开 ISS 。此处提到了 Windows 7 的详细信息

http://helpdeskgeek.com/windows-7/turn-on-microsoft-internet-information-services-in-windows-7/

http://helpdeskgeek.com/windows-7/turn-on-microsoft-internet-information-services-in-windows-7/