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

3

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.

c#
excel
interop
asked on Stack Overflow May 23, 2016 by a.ras2002 • edited May 23, 2016 by a.ras2002

2 Answers

2
 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;
answered on Stack Overflow Sep 29, 2016 by abdosup
0

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

answered on Stack Overflow Apr 17, 2020 by Irq Mishell

User contributions licensed under CC BY-SA 3.0