首页 新闻 赞助 找找看

如何从gridview中导出部分数据excel比如链接不导出

0
悬赏园豆:10 [已解决问题] 解决于 2008-12-01 15:31

如何从gridview中导出部分数据excel

比如第一列是链接不用导出来

今日之说的主页 今日之说 | 初学一级 | 园豆:185
提问于:2008-11-29 10:51
< >
分享
最佳答案
0

    protected void Button1_Click(object sender, EventArgs e)
    {
        Export("application/ms-excel", "学生成绩报表.xls");
    }
    private void Export(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

在GridView1.RenderControl(hw);写入前对它进行重新绑定,绑定你要导出的数据.

Astar | 高人七级 |园豆:40805 | 2008-11-29 12:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册