c# - HRESULT 异常 : 0x80010105 (RPC_E_SERVERFAULT) when opening xlsx file

标签 c# excel interop

我有一个让我发疯的异常。

当我尝试以这种方式打开 .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];

我有这个异常(exception)

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 窗口。

最佳答案

 appExcel.Visible = true;
            classeur = appExcel.Workbooks.Open(DB_Path, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            appExcel.Visible = false;

关于c# - HRESULT 异常 : 0x80010105 (RPC_E_SERVERFAULT) when opening xlsx file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37391337/

相关文章:

c# - 如何在 C# 代码中使用传递给回调的 C/C++ native 结构

c# - 从 C# 在同一环境中执行多个命令

c# - await 关键字可以生成并行代码吗?

java - 根据电子表格选择页面上的值 - Java - Selenium Webdriver

java - 无法使用 Selenium webdriver 写入 Excel

c# - PHP网站如何与Java、C#程序高效通信

c# - 允许用户选择要导入的列标题

c# - 当控制流向锁外的 lambda 函数时,锁会被持久化吗?

excel - 返回时 VBA bool 函数类型不匹配

c - 如何使外部 Mathematica 函数可中断?