zoukankan      html  css  js  c++  java
  • C# 导入多个工作薄文件

    DataTable dt = new DataTable();
                    System.Data.DataTable ExcelTable;
                    DataSet dst = new DataSet();
                    string strconn = "";
                
                    if (this.currFileExtension==".xls")//这样判断不太好 暂时未找出判断Excel版本的解决办法
                    {
                        strconn = "provider=microsoft.jet.oledb.4.0;" + "data source=" + currFilePath + ";" + "extended properties=excel 8.0;";
                    }
                    else {
                        strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + currFilePath + ";Extended Properties=\"Excel 12.0;HDR=YES\"";
                    }
                  
                    OleDbConnection objConn = new OleDbConnection(strconn);
                    objConn.Open();
                    System.Data.DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
                    
                    for (int i = 0; i < schemaTable.Rows.Count; i++)
                    {
                        string tableName = schemaTable.Rows[i][2].ToString().Trim();//获取 Excel 的表名,默认值是sheet1
                        string strSql = "select * from [" + tableName + "]";
                        OleDbDataAdapter myData = new OleDbDataAdapter(strSql, objConn);
                        myData.Fill(dst, tableName);//填充数据
                        ExcelTable = dst.Tables[tableName];
                        dt = dst.Tables[tableName];
                        objConn.Close();
                        --循环调用写入数据库
                       
                    }
    

      

  • 相关阅读:
    poj2739
    poj1469
    poj2010
    poj1179
    poj1778
    使用数组实现ArrayList的效果
    zgb老师关于java集合的总结
    jah老师中关于集合的总结
    继承一个类或者是实现一个接口注意点
    5、Iterator迭代器的使用
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/3014360.html
Copyright © 2011-2022 走看看