问题描述
我在 Windows Server 2008 和 2012 上运行时保存 Excel 电子表格时遇到问题,但该项目可在本地 PC(Windows 7,8 或 10)上运行
I'm having issues with saving an excel spreadsheet when running on the Windows server 2008 and 2012 but this project its working on local pc (Windows 7,8 or 10)
C# 源代码
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Workbooks.Add();
Microsoft.Office.Interop.Excel.Worksheet excelWorkSheet = excelWorkBook.Worksheets.Add();
excelWorkSheet.Name = "blablabla";
//added cells data
excelWorkBook.SaveAs(excelPath.ToString());
excelWorkBook.Close();
excelApp.Quit();
错误提示
来自 HRESULT 的异常:0x800A03ECSystem.Runtime.InteropServices.COMException (0x800A03EC):异常来自 HRESULT:0x800A03EC 在Microsoft.Office.Interop.Excel._Workbook.SaveAs(对象文件名,对象文件格式、对象密码、对象 WriteResPassword、对象ReadOnlyRecommended、对象创建备份、XlSaveAsAccessMode访问模式、对象冲突解决、对象 AddToMru、对象TextCodepage, Object TextVisualLayout, Object Local)
推荐答案
这个错误是因为本地电脑和服务器的office版本不同.我用的是office 2012参考(microsoft office interop excel 14)但是服务器的版本不同(microsoft office interop excel 12)
This error is due to the fact that the local pc and the server have different office versions.I used the office 2012 references (microsoft office interop excel 14) but the server has a different version (microsoft office interop excel 12)
步骤 1) 我安装了相同的办公版本.(v.12)
Step 1) I installed the same office versions. (v.12)
步骤 2) 在Microsoft Excell 应用程序属性"窗口中选择交互式用户"选项.
Step 2) Select "The interactive user" option in "Microsoft Excell Application Properties" window.https://msdn.microsoft.com/en-us/library/windows/desktop/ms686587(v=vs.85).aspx
这篇关于C# System.Runtime.InteropServices.COMException (0x800A03EC): 来自 HRESULT 的异常:0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!