1.目的,为了读取excel文件中大量的数据,并显示在页面上:

    protected void Page_Load(object sender, EventArgs e)
    {
        // excel文件的地址            
        string xlsPath = Server.MapPath("App_Data/aa.xls");
        // 连接字符处
        string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Extended Properties=Excel 8.0;" + "data source=" + xlsPath;
        // 查询语句,Sheet1指定的是那个sheet
        string sql = "SELECT * FROM [Sheet1$A1:M30]";
        DataSet ds = new DataSet();

        // 查询数据
        OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);

        // 填充DataSet        
        da.Fill(ds);         
        // 输出,绑定数据
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }

   注释:

用于 Extended Properties 值的有效 Excel 版本。
对于 Microsoft Excel
8.0 (97)、9.0 (2000) 和 10.0 (2002) 工作簿,请使用 Excel 8.0
对于 Microsoft Excel
5.07.0 (95) 工作簿,请使用 Excel 5.0
对于 Microsoft Excel
4.0 工作簿,请使用 Excel 4.0
对于 Microsoft Excel
3.0 工作簿,请使用 Excel 3.0

 本文参考了:晓风残月的博客,url:http://zt.cnblogs.com/page/42229/

posted on 2008-09-23 11:09  Stym--闫生  阅读(1150)  评论(0编辑  收藏  举报