zoukankan      html  css  js  c++  java
  • C#导入Excel|读取Excel方法

    OleDbConnection读取

    /// <summary>
          /// 返回Excel数据源
          /// </summary>
          /// <param name="filename">文件路径</param>
          /// <param name="TSql">TSql</param>
          /// <returns>DataSet</returns>
          public static DataSet ExcelToDataSet(string filename, string TSql)
          {
              DataSet ds;
              string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;data source=" + filename;
              OleDbConnection myConn = new OleDbConnection(strCon);
              string strCom = TSql;
              myConn.Open();
              OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
              ds = new DataSet();
              myCommand.Fill(ds);
              myConn.Close();
              return ds;
          }
          写sql语句
              string TSql = "SELECT  * FROM [sheel1$]";
            //读取数据
            DataTable table = ExcelToDataSet(fullPath, TSql).Tables[0];
     
  • 相关阅读:
    [BZOJ 2820]YY的GCD
    [POI 2007]ZAP-Queries
    [USACO 04OPEN]MooFest
    [HAOI 2011]Problem b
    [COGS 2258][HZOI 2015]复仇的序幕曲
    [UOJ 41]【清华集训2014】矩阵变换
    [POJ 3487]The Stable Marriage Problem
    [POJ 3252]Round Numbers
    [COGS 1799][国家集训队2012]tree(伍一鸣)
    [SDOI 2011]计算器
  • 原文地址:https://www.cnblogs.com/yasenjan/p/7464282.html
Copyright © 2011-2022 走看看