예제 #1
0
        /// <summary>
        /// 读取Excel单个表方法
        /// </summary>
        /// <param name="filePath">Excel物理路径</param>
        /// <param name="index">默认读取第一张表 index=0,可自定义,注意隐藏表的位置</param>
        /// <param name="isHead">默认将第一行转为表头,可修改为false</param>
        /// <returns></returns>
        public static DataTable ExcelToDataTable(string filePath, int index = 0, bool isHead = true)
        {
            var wk = NExcel.ReadExcel(filePath);
            //读取当前表数据
            var dt = wk.ReadWorkSheet(index, isHead);

            return(dt);
        }
예제 #2
0
        /// <summary>
        /// Excel读取方法例子
        /// </summary>
        /// <param name="filePath">路径</param>
        /// <returns></returns>
        public static DataSet ExcelToDataSetExample(string filePath)
        {
            DataSet ds        = new DataSet();
            string  extension = Path.GetExtension(filePath);
            var     wk        = NExcel.ReadExcel(filePath);
            var     count     = wk.NumberOfSheets;

            for (int i = 0; i < count; i++)
            {
                ds.Tables.Add(wk.ReadWorkSheet(i, true));
            }
            return(ds);
        }