.NET中讀取Excel文件的數(shù)據(jù)及excelReader應(yīng)用
更新時(shí)間:2013年02月01日 15:51:25 作者:
輕量,快速的C#編寫的庫讀取Microsoft Excel文件,這對讀取大量excel文件的朋友們很有幫助而且可以學(xué)習(xí)下ExcelDataReader的應(yīng)用,感興趣的朋友可以了解下,或許對你有所幫助
項(xiàng)目介紹
輕量,快速的C#編寫的庫讀取Microsoft Excel文件('97-2007)。
跨平臺(tái):
- 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()
輕量,快速的C#編寫的庫讀取Microsoft Excel文件('97-2007)。
跨平臺(tái):
- Windows with .Net Framework 2
- Windows Mobile with Compact Framework
- Linux, OS X, BSD with Mono 2+
如何使用
C# 代碼:
復(fù)制代碼 代碼如下:
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 代碼:
復(fù)制代碼 代碼如下:
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客戶端導(dǎo)出Excel實(shí)現(xiàn)代碼及注意事項(xiàng)
- .Net中導(dǎo)出數(shù)據(jù)到Excel(asp.net和winform程序中)
- asp.net生成Excel并導(dǎo)出下載五種實(shí)現(xiàn)方法
- C#數(shù)據(jù)導(dǎo)入/導(dǎo)出Excel文件及winForm導(dǎo)出Execl總結(jié)
- ASP.NET下將Excel表格中的數(shù)據(jù)規(guī)則的導(dǎo)入數(shù)據(jù)庫思路分析及實(shí)現(xiàn)
- ASP.NET導(dǎo)出Excel打開時(shí)提示:與文件擴(kuò)展名指定文件不一致解決方法
- asp.net Grid 導(dǎo)出Excel實(shí)現(xiàn)程序代碼
- C#實(shí)現(xiàn)EXCEL數(shù)據(jù)到TXT文檔的轉(zhuǎn)換
相關(guān)文章
告別ADO.NET實(shí)現(xiàn)應(yīng)用系統(tǒng)無縫切換的煩惱(總結(jié)篇)
說起ADO.NET,就扯上了數(shù)據(jù)庫訪問類庫了,現(xiàn)在的每個(gè)項(xiàng)目的數(shù)據(jù)庫訪問類應(yīng)該說都很強(qiáng)的了,經(jīng)常就聽到說我的我們的數(shù)據(jù)庫訪問類怎么怎么強(qiáng)大而且支持多數(shù)據(jù)庫,現(xiàn)在的大家做的項(xiàng)目里用的數(shù)據(jù)庫訪問類庫我想也都是支持多數(shù)據(jù)庫吧,支持到什么程度我就不知道了2009-11-11
ASP.NET Core跨站登錄重定向的實(shí)現(xiàn)新姿勢
這篇文章主要給大家介紹了關(guān)于ASP.NET Core實(shí)現(xiàn)跨站登錄重定向的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07
基于SignalR的消息推送與二維碼掃描登錄實(shí)現(xiàn)代碼
這篇文章主要介紹了基于SignalR的消息推送與二維碼掃描登錄實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-02-02
asp.net錯(cuò)誤捕獲(錯(cuò)誤處理)page_error事件使用方法
Page_Error事件提供了一種捕獲頁面級(jí)錯(cuò)誤的方法。對于錯(cuò)誤的處理,您可以只是顯示錯(cuò)誤信息(正如下面的示例代碼所示),也可以記錄事件或執(zhí)行某個(gè)其他操作2014-01-01
WPF實(shí)現(xiàn)定時(shí)刷新UI界面功能
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)定時(shí)刷新UI界面功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
MVC4制作網(wǎng)站教程第三章 瀏覽用戶組操作3.1
這篇文章主要為大家詳細(xì)介紹了MVC4制作網(wǎng)站教程,瀏覽用戶組功能的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08

