首页 > 代码库 > 批量导入数据.net
批量导入数据.net
源网址:http://exceldatareader.codeplex.com/
参考如下:
NUGET引用
Note
Please try the latest source from the repo before reporting issues as there have been recent changes.
Also, if you are reporting an issue it is really useful if you can supply an example excel file as this makes debugging much easier and without it we may not be able to resolve any problems.
How to use
C# code :
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.TablesDataSet result = excelReader.AsDataSet();//...//4. DataSet - Create column names from first rowexcelReader.IsFirstRowAsColumnNames = true;DataSet result = excelReader.AsDataSet();//5. Data Reader methodswhile (excelReader.Read()){ //excelReader.GetInt32(0);}//6. Free resources (IExcelDataReader is IDisposable)excelReader.Close();
VB.NET Code:
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.TablesDim result As DataSet = excelReader.AsDataSet()‘...‘4. DataSet - Create column names from first rowexcelReader.IsFirstRowAsColumnNames = TrueDim result As DataSet = excelReader.AsDataSet()‘5. Data Reader methodsWhile excelReader.Read() ‘excelReader.GetInt32(0);End While‘6. Free resources (IExcelDataReader is IDisposable)excelReader.Close()
批量导入数据.net
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。