我有一个例外,这让我发疯。
当我尝试以这种方式打开 .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 窗口。