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;
        }

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-08-16
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2021-07-16
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
相关资源
相似解决方案