现在的位置: 首页 > 综合 > 正文

.net 读取xls中的数据

2018年02月11日 ⁄ 综合 ⁄ 共 596字 ⁄ 字号 评论关闭

 //获取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;
        }

抱歉!评论已关闭.