打开xlsx文件时出现HRESULT异常:0x80010105(RPC_E_SERVERFAULT)

时间:2016-05-23 12:42:42

标签: c# excel interop

我有这个让你疯狂的例外。

当我尝试以这种方式打开.xlsx文件时

C:\Program Files\PostgreSQL\9.5\data\pg_log

我有这个例外

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];

任何人都可以给我一个解决方案,为什么会这样?

Ps:我正在使用Interop库打开Excel。

编辑:显然,如果我设置 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 它有效,但我不希望Excel窗口出现。

2 个答案:

答案 0 :(得分:0)

   @Override
    public synchronized Servlet loadServlet() throws ServletException {
        if (singleThreadModel) {
            Servlet instance;
            try {
                instance = existing.getClass().newInstance();
            } catch (InstantiationException e) {
                throw new ServletException(e);
            } catch (IllegalAccessException e) {
                throw new ServletException(e);
            }
            instance.init(facade);
            return instance;
        } else {
            if (!instanceInitialized) {
                existing.init(facade);
                instanceInitialized = true;
            }
            return existing;
        }
    }

答案 1 :(得分:0)

我仍然没有找到解决方案,但是当我使用abdosup中的解决方法时,Excel窗口显示了片刻,并且存在用户在打开工作簿时按ctrl + v键加载可能会崩溃的危险。

请查看:

appExcel.Visible = true;
OldExcelTop = appExcel.Top;
appExcel.Top = 10000;
appExcel.OnKey("^v", "");
classeur = appExcel.Workbooks.Open(DB_Path, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
appExcel.Visible = false;
appExcel.OnKey("^v", Type.Missing);
appExcel.Top = OldExcelTop ;

我在 Disable copy(ctrl+c), paste(ctrl+v),cut(ctrl+x) in excel