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

Excel的导出操作

2011年04月08日 ⁄ 综合 ⁄ 共 1387字 ⁄ 字号 评论关闭

下面的代码展示了如何将Excel内容显示到GridView中:
aspx代码:

.aspx

.cs代码:

protected void btnImport_Click(object sender, EventArgs e)
        
{
            
string Path = f_path.Value;
            
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
            OleDbConnection conn 
= new OleDbConnection(strConn);
            conn.Open();
            
string strExcel = "";
            OleDbDataAdapter myCommand 
= null;
            DataSet ds 
= null;
            strExcel 
= "select * from [sheet1$]";
            myCommand 
= new OleDbDataAdapter(strExcel, strConn);
            ds 
= new DataSet();
            myCommand.Fill(ds, 
"table1");

            gv_list.DataSource 
= ds;
            gv_list.DataBind();

        }

抱歉!评论已关闭.