ExcelDataReader可以读取 Microsoft Excel 文件 ('97-2007),支持Windows .Net Framework 2 +、 Windows Mobile with Compact Framework
、 Linux, OS X, BSD with Mono 2。项目地址:http://exceldatareader.codeplex.com/
使用方法非常简单:
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader ExcelReader = ExcelReaderFactory.CreateBinaryReader(stream);
//...
//2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader ExcelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
//...
//3. DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = ExcelReader.AsDataSet();
//...
//4. DataSet - Create column names from first row
ExcelReader.IsFirstRowAsColumnNames = true;
DataSet result = ExcelReader.AsDataSet();
//5. Data Reader methods
while (ExcelReader.Read())
{
//ExcelReader.GetInt32(0);
}
//6. Free resources (IExcelDataReader is IDisposable)
ExcelReader.Close();