Project Introduction
Simple and quick C # library to read Microsoft Excel files ('97-2007 ).
Cross-platform:
-Windows with. Net Framework 2
-Windows Mobile with Compact Framework
-Linux, OS X, BSD with Mono 2 +
How to Use
C # code:
Copy codeThe Code is as follows:
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 ();
VB. NET code:
Copy codeThe Code is as follows:
Dim stream As FileStream = File. Open (filePath, FileMode. Open, FileAccess. Read)
'1. Reading from a binary Excel file ('97-2003 format; *. xls)
Dim excelReader As IExcelDataReader = ExcelReaderFactory. CreateBinaryReader (stream)
'...
'2. Reading from a OpenXml Excel file (2007 format; *. xlsx)
Dim excelReader As IExcelDataReader = ExcelReaderFactory. CreateOpenXmlReader (stream)
'...
'3. DataSet-The result of each spreadsheet will be created in the result. Tables
Dim result As DataSet = excelReader. AsDataSet ()
'...
'4. DataSet-Create column names from first row
ExcelReader. IsFirstRowAsColumnNames = True
Dim result As DataSet = excelReader. AsDataSet ()
'5. Data Reader methods
While excelReader. Read ()
'Excelreader. GetInt32 (0 );
End While
'6. Free resources (IExcelDataReader is IDisposable)
ExcelReader. Close ()