.NET中讀取Excel文件的數(shù)據(jù)及excelReader應(yīng)用
輕量,快速的C#編寫(xiě)的庫(kù)讀取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()
- ASP.NET(C#)讀取Excel的文件內(nèi)容
- .net客戶(hù)端導(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ù)庫(kù)思路分析及實(shí)現(xiàn)
- ASP.NET導(dǎo)出Excel打開(kāi)時(shí)提示:與文件擴(kuò)展名指定文件不一致解決方法
- asp.net Grid 導(dǎo)出Excel實(shí)現(xiàn)程序代碼
- C#實(shí)現(xiàn)EXCEL數(shù)據(jù)到TXT文檔的轉(zhuǎn)換
相關(guān)文章
防止在服務(wù)器處理完成之前用戶(hù)多次點(diǎn)擊提交按鈕處理代碼
在提交表單時(shí),如果網(wǎng)頁(yè)速度過(guò)慢或者其他原因,用戶(hù)多次提交能導(dǎo)致數(shù)據(jù)的修改,怎么解決這個(gè)問(wèn)題呢,接下來(lái)將為您解決這個(gè)問(wèn)題,需要的朋友可以了解下2012-12-12關(guān)于Metalama使用Fabric操作項(xiàng)目或命名空間的問(wèn)題
Metalama是一個(gè)基于微軟編譯器Roslyn的元編程的庫(kù),可以解決我在開(kāi)發(fā)中遇到的重復(fù)代碼的問(wèn)題,這篇文章主要介紹了Metalama使用Fabric操作項(xiàng)目或命名空間,需要的朋友可以參考下2022-04-04ASP.NET圖片處理三類(lèi)經(jīng)典問(wèn)題
這篇文章主要介紹了ASP.NET圖片處理三類(lèi)經(jīng)典問(wèn)題,驗(yàn)證碼的實(shí)現(xiàn)、給圖片加文字,最后一個(gè)就是生成縮略圖,感興趣的小伙伴們可以參考一下2015-09-09.NET Core利用動(dòng)態(tài)代理實(shí)現(xiàn)AOP(面向切面編程)
用動(dòng)態(tài)代理可以做AOP(面向切面編程),進(jìn)行無(wú)入侵式實(shí)現(xiàn)自己的擴(kuò)展業(yè)務(wù),調(diào)用者和被調(diào)用者之間的解耦,提高代碼的靈活性和可擴(kuò)展性。本文將為大家詳細(xì)介紹實(shí)現(xiàn)的方法,感興趣的可以學(xué)習(xí)一下2022-01-01IIS實(shí)現(xiàn)反向代理時(shí)Cookie域的設(shè)置方法
這篇文章主要給大家介紹了關(guān)于IIS實(shí)現(xiàn)反向代理時(shí)Cookie域的設(shè)置方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04Asp.NetCore3.1開(kāi)源項(xiàng)目升級(jí)為.Net6.0的方法實(shí)現(xiàn)
自從.Net6.0出來(lái)后,一直想之前開(kāi)發(fā)的項(xiàng)目升級(jí).Net6.0,本文就詳細(xì)的介紹一下如何將Asp.NetCore3.1開(kāi)源項(xiàng)目升級(jí)為.Net6.0,感興趣的小伙伴們可以參考一下2021-12-12簡(jiǎn)單Web service 身份驗(yàn)證解決方案
問(wèn)題提出:為了構(gòu)建一個(gè)安全的web服務(wù),需要對(duì)調(diào)用方進(jìn)行身份驗(yàn)證,只讓通過(guò)審核的用戶(hù)調(diào)用web服務(wù)。2009-05-05