【发布时间】:2020-04-17 18:13:56
【问题描述】:
我有一个让我发疯的异常。
当我尝试以这种方式打开 .xlsx 文件时
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
string v = "path\File.xlsx";
Workbook wb = app.Workbooks.Open(v); //This triggers the exception
app.Visible = true;
Worksheet sh = wb.Sheets[1];
我有这个例外
Error: System.Runtime.InteropServices.COMException (0x80010105): Server launches an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object
at MainWindow.loadFile(String v) in MainWindow.cs:line 139
谁能给我一个解决方案,为什么会这样?
Ps:我正在使用 Interop 库打开 Excel。
编辑:显然如果我设置
app.Visible = true; 可以,但我不希望 Excel 窗口出现。
【问题讨论】:
-
什么是
v?您可以发布该变量的确切内容吗? -
v 是文件的路径
-
听起来像是 Excel 本身通过 COM 返回的错误。如果您在 Excel 中手动打开文件会怎样?
-
没什么异常,如果我手动打开文件,它就会打开
-
你有没有为这个问题找到一个更优雅的解决方案?