| 发表于:2007-01-29 15:12:43 楼主 |
新的excel的connectionstring与原来的写法不同,因此想在确定connectionstring前先获得本机安装的excel版本 private string checkexcelversion() { type type; object excel; string version = " "; type = type.gettypefromprogid( "excel.application "); string str = type.tostring(); if (type == null) { messagebox.show( "没有安装excel "); } else { excel = activator.createinstance(type); if (excel == null) { messagebox.show( "创建对象出错 "); } else { version = type.getproperty( "version ").getvalue(excel, null).tostring(); //type.getproperty( "visible ").setvalue(excel, true, null); type.getmethod( "quit ").invoke(excel, null); //gc.collect(); } } return version.trim(); } 在一台机器上测试没有问题,但是到另外一台机器上却报 targetinvocationexception 不知道为什么 |
|
|
|
|