C#:加载Excel(待补充)

          string strConn;

                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";

                OleDbConnection OleConn = new OleDbConnection(strConn);

                OleConn.Open();



                System.Data.DataTable sheetNames = OleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });//获得Excel表的架构信息





                String sql = "SELECT * FROM  [" + sheetNames.Rows[0]["TABLE_NAME"] + "]";//可是更改Sheet名称,比如sheet2,等等    



                OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);

                DataSet OleDsExcle = new DataSet();

                OleDaExcel.Fill(OleDsExcle);

                OleConn.Close();

                return OleDsExcle;

 

你可能感兴趣的:(Excel)