zoukankan      html  css  js  c++  java
  • 批量导入数据.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.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 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.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()
    
  • 相关阅读:
    如何使样式CSS不被覆盖 !important
    PHP5中数组函数总结篇
    优化php效率,提高php性能的一些方法
    windows2003 系统下不能识别移动硬盘解决方法
    Sql Server 2000索引问题?
    在网页中调用本地的应用程序
    Sql Server资料收集(摘自http://www.itpub.net)
    利用CSS控制打印
    C#.NET 中的类型转换
    卓越领导力素质训练心得
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4138439.html
Copyright © 2011-2022 走看看