Silverlight -> opening xls, error in InvokeMember("Open", .. ) RRS feed

  • Question


    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?

    Friday, April 29, 2011 9:16 AM


  • Hello, since this is a pure Silverlight question, please post it on http://forums.silverlight.net/. Just some general advices: First make sure you're working with an elevated OOB, which supports COM interop. Also in Silverlight, you have to use dynamic types to perform COM interop.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Yi-Lun Luo Thursday, May 5, 2011 9:14 AM
    Tuesday, May 3, 2011 2:09 AM