C# 读取Excel的数据到DataTable

    FileStream stream = File.Open(strExcelFile, FileMode.Open, FileAccess.Read);
                IExcelDataReader excelReader;
                if (Path.GetExtension(strExcelFile) == ".xls")
                {
                    //1. Reading from a binary Excel file ('97-2003 format; *.xls)
                    excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
                }
                else
                {
                    //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                }                 DataSet result = excelReader.AsDataSet();
                excelReader.Close();
                stream.Close();                 return result.Tables[0];
上一篇:【c#】datatable和dataset区别及用法


下一篇:基于DataTable, Json的额外序列化数据