简体   繁体   中英

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

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.

 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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM