您的位置:程序门 -> .net技术 -> c#



调用excel有问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


调用excel有问题[已结贴,结贴人:hahahoo]
发表于: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
不知道为什么
发表于:2007-01-29 15:48:171楼 得分:50
我这里测试可以,我的环境是excel2003
哪句代码出的异常?
发表于:2007-01-29 16:00:392楼 得分:0
version   =   type.getproperty( "version ").getvalue(excel,   null).tostring();
我用的是excel2007,不过在另外一台机器上测试通过,系统是(vista+office2007)。就是为了这个2007才要做这个判别的
发表于:2007-01-29 16:52:153楼 得分:0
我以前做过97,2000,xp,2003,都是用的excel.application,没有问题,这种写法本来就是保持向后兼容的。是不是excel2007的调用方法不一样????
发表于:2007-01-29 16:52:554楼 得分:0
强悍阿,这么快就用到office2007了
发表于:2007-01-29 17:20:545楼 得分:0
但是我在vista+excel2007上可以查到excel版本
发表于:2007-04-04 14:16:116楼 得分:0
up


快速检索

最新资讯
热门点击