读取excel的方法(可用于批量导入)_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 读取excel的方法(可用于批量导入)

读取excel的方法(可用于批量导入)

 2017/9/1 18:08:53  黑哥_XJ  程序员俱乐部  我要评论(0)
  • 摘要:FileStreamstream=File.Open(filePath,FileMode.Open,FileAccess.Read);//1.ReadingfromabinaryExcelfile('97-2003format;*.xls)IExcelDataReaderexcelReader=ExcelReaderFactory.CreateBinaryReader(stream);//...//2.ReadingfromaOpenXmlExcelfile(2007format;*.xlsx
  • 标签:方法 excel
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();
上一篇: 支付宝:刷公交卡、骑共享单车也能种树了 下一篇: 没有下一篇了!
发表评论
用户名: 匿名