項目介紹
輕量,快速的C#編寫的庫讀取Microsoft Excel文件('97-2007)。
跨平臺:
- Windows with .Net Framework 2
- Windows Mobile with Compact Framework
- Linux, OS X, BSD with Mono 2+
如何使用
C# 代碼:
復制代碼 代碼如下:
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 代碼:
復制代碼 代碼如下:
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()
您可能感興趣的文章:- ASP.NET(C#)讀取Excel的文件內(nèi)容
- .net客戶端導出Excel實現(xiàn)代碼及注意事項
- .Net中導出數(shù)據(jù)到Excel(asp.net和winform程序中)
- asp.net生成Excel并導出下載五種實現(xiàn)方法
- C#數(shù)據(jù)導入/導出Excel文件及winForm導出Execl總結(jié)
- ASP.NET下將Excel表格中的數(shù)據(jù)規(guī)則的導入數(shù)據(jù)庫思路分析及實現(xiàn)
- ASP.NET導出Excel打開時提示:與文件擴展名指定文件不一致解決方法
- asp.net Grid 導出Excel實現(xiàn)程序代碼
- C#實現(xiàn)EXCEL數(shù)據(jù)到TXT文檔的轉(zhuǎn)換