日期:2014-05-20  浏览次数:20796 次

调用EXCEL有问题
新的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();