zoukankan      html  css  js  c++  java
  • 读取excel 可以多个模板同一连接遍历

      public DataTable ExcelToDataSet(string filename, string[] templateNames)
            {
                DataTable dataTable = new DataTable();
                string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                "Extended Properties=Excel 8.0;" +
                                "data source=" + filename;
                OleDbConnection myConn = new OleDbConnection(strCon);
                foreach (string tempName in templateNames)
                {
                    DataTable dataTableTemp = new DataTable();
                    string strCom = " SELECT * FROM [" + tempName + "$]";
                    myConn.Open();
                    OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
                    myCommand.Fill(dataTableTemp);
                    myConn.Close();
                    dataTable.Merge(dataTableTemp);
                }
            
                return dataTable;
            }
  • 相关阅读:
    [USACO 5.5]Hidden Password
    [Codeforces 1016F]Road Projects
    再会,OI
    [TJOI 2018]智力竞赛
    [POI 2009]Lyz
    [NOI 2015]品酒大会
    [NOI 2017]蔬菜
    [NOI 2017]整数
    [NOI 2017]游戏
    [NOI 2017]蚯蚓排队
  • 原文地址:https://www.cnblogs.com/wanyuan8/p/2557631.html
Copyright © 2011-2022 走看看