zoukankan      html  css  js  c++  java
  • 连接excel2003、2007以上版本的excel的方法,返回一个连接字符串

     /// </summary>
            /// <param name="fileName">文件名称</param>
            /// <returns>返回的链接字符串</returns>
            private string GetConnectionString(string fileName)
            {
                string connectString = string.Empty;
                //xls文件的连接字符串
                if (fileName.IndexOf(".xlsx") < 0)
                {
                    connectString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=Yes;'";
                }
                else
                {
                    //xlsx,Excel 2007文件的连接字符串
                    connectString =
                    @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=YES'";
                }
                return connectString;

            }

    其中HDR为YES的时候表示第一行为字段行。

  • 相关阅读:
    2020.11.6
    2020.7.15小日记
    P1536 村村通
    P1510 精卫填海
    P1020 导弹拦截
    P1164 小A点菜
    5.17练习总结
    P1135 奇怪的电梯
    P1101 单词方阵
    P1443 马的遍历
  • 原文地址:https://www.cnblogs.com/lijinchang/p/2306198.html
Copyright © 2011-2022 走看看