Hi everyone,
I need to open an xsl document, edit it and save it as a new file.
I've an error on the line in bold (so i can't open the document)
//here i create workbooks and worksheet
Type ExcelType = Type.GetTypeFromProgID("EXCEL.Application");
objEXLApp = Activator.CreateInstance(ExcelType);
ExcelType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, objEXLApp,
new object[] { false });
ExcelType.InvokeMember("UserControl", System.Reflection.BindingFlags.SetProperty, null, objEXLApp,
new object[] { true });
objBooks = objEXLApp.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objEXLApp, null);
objBook = objBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objBooks, null);
objSheets = objBook.GetType().InvokeMember("Worksheets", BindingFlags.GetProperty, null, objBook, null);
//here I try opening the document
string _filePath = "D:\\Mypath\\MyFileExel.xls";
object[] Parameters = new Object[1];
Parameters[0] = _filePath;
objExcelDoc = objBook.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, objBook, Parameters);
In the last line I got the error:
{"Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))"}
StackTrace = " at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)\r\n at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags...
I can't understand what's the problem.
Any ideas?