晚期绑定Excel组件遇到的麻烦
各位好:
现在为了解决调用Excel COM组件的版本问题,我用了晚期绑定技术,这有一段从MSDN上摘下来的代码:
Type objClassType;
objClassType = Type.GetTypeFromProgID( "Excel.Application ");
objApp_Late = Activator.CreateInstance(objClassType);
//Get the workbooks collection.
objBooks_Late = objApp_Late.GetType().InvokeMember( "Workbooks ",
BindingFlags.GetProperty, null, objApp_Late, null);
//Add a new workbook.
objBook_Late = objBooks_Late.GetType().InvokeMember( "Add ",
BindingFlags.InvokeMethod, null, objBooks_Late, null);
//Get the worksheets collection.
objSheets_Late = objBook_Late.GetType().InvokeMember( "Worksheets ",
BindingFlags.GetProperty, null, objBook_Late, null);
//Get the first worksheet.
Parameters = new Object[1];
Parameters[0] = 1;
objSheet_Late = objSheets_Late.GetType().InvokeMember( "Item ",
BindingFlags.GetProperty, null, objSheets_Late, Parameters);
//Get a range object that contains cell A1.
Parameters = new Object[2];
Parameters[0] = "A1 ";