How to use

王朝学院·作者佚名  2016-05-17
窄屏简体版  字體: 小  |  中  |  大  |  超大  

View Post批量导入数据.net源网址:http://Exceldatareader.codeplex.com/参考如下:NUGET引用

NotePlease 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 useC# 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()

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航