. NET reads Excel file data and excelReader applications

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.