Example #1
0
        /// <summary>
        /// 返回Excel 连接字符串
        /// </summary>
        /// <param name="excelPath">Excel文件 绝对路径</param>
        /// <param name="header">是否把第一行作为列名</param>
        /// <param name="eType">Excel 版本 </param>
        /// <param name="imex">IMEX模式</param>
        /// <returns>返回值</returns>
        public static string GetExcelConnectstring(string excelPath, bool header, ExcelType eType, IMEXType imex)
        {
            if (!MyFileHelper.IsExistFile(excelPath))
                throw new FileNotFoundException("Excel路径不存在!");

            string connectstring;

            string hdr = "NO";
            if (header)
                hdr = "YES";

            if (eType == ExcelType.Excel2003)
                connectstring = "Provider=Microsoft.Jet.OleDb.4.0; data source=" + excelPath +
                                ";Extended Properties='Excel 8.0; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() + "'";
            else
                connectstring = "Provider=Microsoft.ACE.OLEDB.12.0; data source=" + excelPath +
                                ";Extended Properties='Excel 12.0 Xml; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() +
                                "'";

            return connectstring;
        }
Example #2
0
        /// <summary>
        /// 返回Excel 连接字符串
        /// </summary>
        /// <param name="excelPath">Excel文件 绝对路径</param>
        /// <param name="header">是否把第一行作为列名</param>
        /// <param name="eType">Excel 版本 </param>
        /// <param name="imex">IMEX模式</param>
        /// <returns></returns>
        public static string GetExcelConnectstring(string excelPath, bool header, ExcelType eType, IMEXType imex)
        {
            if (!FileUtil.IsExistFile(excelPath))
            {
                throw new FileNotFoundException("Excel路径不存在!");
            }

            string connectstring = string.Empty;

            string hdr = "NO";

            if (header)
            {
                hdr = "YES";
            }

            if (eType == ExcelType.Excel2003)
            {
                connectstring = "Provider=Microsoft.Jet.OleDb.4.0; data source=" + excelPath + ";Extended Properties='Excel 8.0; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() + "'";
            }
            else
            {
                connectstring = "Provider=Microsoft.ACE.OLEDB.12.0; data source=" + excelPath + ";Extended Properties='Excel 12.0 Xml; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() + "'";
            }

            return(connectstring);
        }
Example #3
0
        public static string GetExcelConnectstring(string excelPath, bool header, ExcelType eType, IMEXType imex)
        {
            if (!FileUtil.IsExistFile(excelPath))
            {
                throw new FileNotFoundException("Excel路径不存在!");
            }
            string str = "NO";

            if (header)
            {
                str = "YES";
            }
            if (eType == ExcelType.const_0)
            {
                return(string.Concat(new object[] { "Provider=Microsoft.Jet.OleDb.4.0; data source=", excelPath, ";Extended Properties='Excel 8.0; HDR=", str, "; IMEX=", imex.GetHashCode(), "'" }));
            }
            return(string.Concat(new object[] { "Provider=Microsoft.ACE.OLEDB.12.0; data source=", excelPath, ";Extended Properties='Excel 12.0 Xml; HDR=", str, "; IMEX=", imex.GetHashCode(), "'" }));
        }
Example #4
0
        /// <summary>
        /// 返回Excel连接字符串
        /// </summary>
        /// <param name="excelPath">Excel文件绝对路径</param>
        /// <param name="header">是否第一行为列名</param>
        /// <param name="eType">Excel版本</param>
        /// <param name="imex">IMEX模式</param>
        /// <returns></returns>
        public string GetExcelConnectionString(string excelPath, bool header, ExcelType eType, IMEXType imex)
        {
            if (string.IsNullOrEmpty(excelPath))
            {
                throw new ArgumentNullException("Excel路径字符串为空");
            }
            if (!System.IO.File.Exists(excelPath))
            {
                throw new FileNotFoundException(string.Format("Excel文件不存在,路径为:{0}", excelPath));
            }

            string connectionString = "";
            string hdr = "NO";

            if (header)
            {
                hdr = "YES";
            }

            if (eType == ExcelType.Excel_2003)
            {
                connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=" + excelPath +
                                   ";Extended Properties='Excel 8.0; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() + "'";
            }
            else
            {
                connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; data source=" + excelPath +
                                   ";Extended Properties='Excel 12.0 Xml; HDR=" + hdr + "; IMEX=" + imex.GetHashCode() + "'";
            }
            return(connectionString);
        }