手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >.NET中读取Excel文件的数据及excelReader应用
.NET中读取Excel文件的数据及excelReader应用
摘要:项目介绍轻量,快速的C#编写的库读取MicrosoftExcel文件('97-2007)。跨平台:-Windowswith.NetFrame...

项目介绍

轻量,快速的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()

【.NET中读取Excel文件的数据及excelReader应用】相关文章:

asp.net后台如何动态添加JS文件和css文件的引用?

用.Net的File控件上传文件的解决方案

ASP.NET技巧:做个DataList可分页的数据源

ASP.NET中TreeView用法

ASP.Net下载大文件的实现方法

ASP.NET中数据库操作初步

asp.net读取excel文件的三种方法示例

读取TXT文件内容的方法

.NET(C#)连接各类数据库代码-集锦

ASP.NET如何获取两个日期之间的天数

精品推荐
分类导航