Exemplo n.º 1
0
        /// <summary>
        /// 获取Excel文件中指定工作表的列
        /// </summary>
        /// <param name="excelPath"></param>
        /// <param name="eType"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public static List <string> GetColumnsList(string excelPath, MdExcelHelper.ExcelType eType, string table)
        {
            string    excelConnectstring = MdExcelHelper.GetExcelConnectstring(excelPath, true, eType);
            DataTable readerSchema;

            using (OleDbConnection oleDbConnection = new OleDbConnection(excelConnectstring))
            {
                oleDbConnection.Open();
                readerSchema = MdExcelHelper.GetReaderSchema(table, oleDbConnection);
            }
            return((from DataRow dr in readerSchema.Rows
                    let columnName = dr["ColumnName"].ToString()
                                     let datatype = ((OleDbType)dr["ProviderType"]).ToString()
                                                    let netType = dr["DataType"].ToString()
                                                                  select columnName).ToList <string>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 返回Excel工作表名
        /// </summary>
        /// <param name="excelPath"></param>
        /// <param name="eType"></param>
        /// <returns></returns>
        public static List <string> GetExcelTablesName(string excelPath, MdExcelHelper.ExcelType eType)
        {
            string excelConnectstring = MdExcelHelper.GetExcelConnectstring(excelPath, true, eType);

            return(MdExcelHelper.GetExcelTablesName(excelConnectstring));
        }
Exemplo n.º 3
0
 /// <summary>
 /// 返回Excel 连接字符串 [IMEX=1]
 /// </summary>
 /// <param name="excelPath"></param>
 /// <param name="header"></param>
 /// <param name="eType"></param>
 /// <returns></returns>
 public static string GetExcelConnectstring(string excelPath, bool header, MdExcelHelper.ExcelType eType)
 {
     return(MdExcelHelper.GetExcelConnectstring(excelPath, header, eType, MdExcelHelper.IMEXType.ImportMode));
 }
Exemplo n.º 4
0
        /// <summary>
        /// EXCEL所有工作表导入DataSet
        /// </summary>
        /// <param name="excelPath"></param>
        /// <param name="header"></param>
        /// <param name="eType"></param>
        /// <returns></returns>
        public static DataSet ExcelToDataSet(string excelPath, bool header, MdExcelHelper.ExcelType eType)
        {
            string excelConnectstring = MdExcelHelper.GetExcelConnectstring(excelPath, header, eType);

            return(MdExcelHelper.ExcelToDataSet(excelConnectstring));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 返回Excel第一个工作表表名
        /// </summary>
        /// <param name="excelPath"></param>
        /// <param name="eType"></param>
        /// <returns></returns>
        public static string GetExcelFirstTableName(string excelPath, MdExcelHelper.ExcelType eType)
        {
            string excelConnectstring = MdExcelHelper.GetExcelConnectstring(excelPath, true, eType);

            return(MdExcelHelper.GetExcelFirstTableName(excelConnectstring));
        }