.NET中读取Excel文件的数据及excelReader应用


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



相关阅读:
MySQL使用命令备份和还原数据库
c# Graphics使用方法(画圆写字代码)
HTML5中的postMessage API基本使用教程
php中smarty模板条件判断用法实例
HTML5新增的Css选择器、伪类介绍
JavaScript字符串常用的方法
Javascript玩转继承(二)
jQuery事件绑定与解除绑定实现方法
一行命令搞定node.js 版本升级
ThinkPHP模板替换与系统常量及应用实例教程
举例说明如何为JavaScript的方法参数设置默认值
Win8如何使用自带的开始屏幕上的SkyDrive应用
Win8系统单击变双击怎么修复 Win8系统单击变双击修复方法
如何实现修改密码时密码框显示保存到cookie的密码
快速导航

Copyright © 2016 phpStudy |