zoukankan      html  css  js  c++  java
  • C#判断不同版本的Excel(转)

    1、判断是否安装的是Excel2000:

                     RegistryKey regk = Registry.LocalMachine;

     

    RegistryKey akey =regk .OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\9.0\\Word\\InstallRoot\\"); //检查本机是否安装Office2000if(

     

    akey !=null) { string file00 =akey .GetValue("Path").ToString(); if (File.Exists(file00 +"Excel.exe")) { ifused =true; } }

     2、判断是否安装的是Excel2003:

    RegistryKey regk = Registry.LocalMachine;

    RegistryKey bkey =regk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");

      //检查本机是否安装Office2003

    if (bkey !=null) { string file00 =bkey.GetValue("Path").ToString();

    if (File.Exists(file03 +"Excel.exe"))

                            {ifused=true;} } 

    3、判断是否安装的是Excel2007: 

     RegistryKey regk = Registry.LocalMachine;

    RegistryKey ckey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");

       

     

    if (akeytwo !=null) { string file07 =ckey.GetValue("Path").ToString(); if (File.Exists(file07 +"Excel.exe")) { ifused =true; } }

     4、2003或者2007下的动态拼接连接字符串:

       DataSet ds =new DataSet();

    string strConn=""; if(ExistsRegedit03()) { strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strpath + ";" + "Extended Properties=Excel 8.0;"; }else if(ExistsRegedit07()) { strConn = "Provider=Microsoft.Ace.OLEDB.12.0;" + "Data Source=" + strpath + ";" + "Extended Properties=Excel 12.0;"; } OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [RelationerTable$]", strConn); myCommand.Fill(ds); DataTable dt = ds.Tables[0];

  • 相关阅读:
    部署阿里云服务器流程小结
    爬虫中代理的设置问题介绍
    简析 __init__、__new__、__call__ 方法
    Python3.* 和Python2.*的区别
    解决k8s svcat ServiceInstance 删除不掉问题
    k8s dashboard部署,使用traefik暴露问题记录
    python中all函数得用法
    使用Hexo+github搭建个人博客大坑
    使用scrapy爬取百度招聘
    还是爬虫,使用的是selenium,爬取的是智联,爬取速度灰常慢...
  • 原文地址:https://www.cnblogs.com/jinmingjie/p/2560970.html
Copyright © 2011-2022 走看看