日期:2014-05-17  浏览次数:20518 次

Gridview B/S 导出到Excel 会讲的来~会翻译的GO GO GO!

第一题:找人详细翻译一下 下面每句话的作用函数的作用 gridview导出到Excel(下面的功能能实现汉字无乱码)

C# code


//下面代码将gridview导出到excel

#region   //将某天的详细数据导出到EXCEL
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = false;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", 

"attachment;filename=pkmv_de.xls");
        Response.ContentEncoding = 

System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "application/ms-excel";
        Response.Write("<meta http-equiv=Content-Type 

content=\"text/html; charset=GB2312\">");
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new 

System.IO.StringWriter();
        HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter

(oStringWriter);
        GridView2.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());
        Response.End();
    }
 public override void VerifyRenderingInServerForm(Control 

control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
    #endregion





--------------继续提问---------------
Gridview有分页会导致数据溢出;
怎么在又分页的情况下 导出所有数据 和部分数据 有的请支招;
如果有能判断出导出数据的行 列 Gridview详细信息更佳! 分数给追加 哦!



------解决方案--------------------
Response.Write("<meta http-equiv=Content-Type 

content=\"text/html; charset=GB2312\">");
这个去掉,你是哪几句不懂,懒得全部备注.关键的几句跟你说下
Response.Charset = "GB2312";//这个编码你应该是知道的
Response.AppendHeader("Content-Disposition", "attachment;filename=pkmv_de.xls");//告诉浏览器是下载
Response.ContentType = "application/ms-excel";//告诉浏览器下载为excel格式