问题
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