Excel 反射 后期绑定 问题.
Type _excelAppType;
object _excel;
object _documents;
try {
_excelAppType = Type.GetTypeFromProgID("Excel.Application",true);
_excel = Activator.CreateInstance(_excelAppType, false);
_documents = _excelAppType.InvokeMember("Documents",
BindingFlags.GetProperty, null, _excel, null);} catch (Exception er) {
string result = er.Message;
}
调用_excelAppType.InvokeMember("Documents",BindingFlags.GetProperty, null, _excel, null);
出现错误:Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
大家有谁遇到过吗?有什么解决办法.
------解决方案--------------------
确实没有Documents属性吧,参考从MSDN上查到的Excel 2007 Object Model,Excel的文档貌似是Workbooks或者Workbook吧……
参考:http://msdn.microsoft.com/zh-cn/library/bb332345(en-us).aspx