.net 读取xls中的数据

来源:互联网 发布:smali转换java 编辑:程序博客网 时间:2024/05/17 22:18
 //获取xls中的数据
        public static DataTable GetContentTable(string xlspath)
        {
            DataTable table = new DataTable();
            //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlspath + ";" +
              //"Extended Properties='Excel 12.0;HDR=No'";
            string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + xlspath + ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'";
            DataSet ds = new DataSet();
            OleDbDataAdapter oada = new OleDbDataAdapter("select * from [Sheet1$]", strConn);
            oada.Fill(ds);
            table = ds.Tables[0];
            return table;
        }

原创粉丝点击