Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT) when opening xlsx file

℡╲_俬逩灬. 提交于 2020-05-13 11:52:15

问题


I have this exception that is driving me crazy.

When I try to open a .xlsx file this way

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

I have this 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

Anyone could give me a solution and why is this happening?

Ps: I'm using Interop library to open Excel.

Edit: Apparently if I set app.Visible = true; it works, but I don't want that the Excel window appears.


回答1:


 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;



回答2:


I still don't find solution but when I use workaround from abdosup, Excel window was show for tiny moment and there was dangerous that user in open workbook moment press ctrl+v key loading could crash.

Please look at:

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 ;

i found this solution in Disable copy(ctrl+c), paste(ctrl+v),cut(ctrl+x) in excel



来源:https://stackoverflow.com/questions/37391337/exception-from-hresult-0x80010105-rpc-e-serverfault-when-opening-xlsx-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!