/// <summary>
/// 需要重写GridView所在的页面的VerifyRenderingInServerForm事件
/// public override void VerifyRenderingInServerForm(Control control)
/// { }
/// </summary>
private void ExportToExcel(GridView gv, string fileName)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); ;
Response.ContentType = "application/vnd.xls";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gv.RenderControl(hw);
Response.Output.Write(tw.ToString());
Response.Flush();
Response.End();
}
/// <summary>
/// 配合 Gridvidew 汇出Excel使用
/// </summary>
public override void VerifyRenderingInServerForm(Control control)
{ }
/// 需要重写GridView所在的页面的VerifyRenderingInServerForm事件
/// public override void VerifyRenderingInServerForm(Control control)
/// { }
/// </summary>
private void ExportToExcel(GridView gv, string fileName)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); ;
Response.ContentType = "application/vnd.xls";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
gv.RenderControl(hw);
Response.Output.Write(tw.ToString());
Response.Flush();
Response.End();
}
/// <summary>
/// 配合 Gridvidew 汇出Excel使用
/// </summary>
public override void VerifyRenderingInServerForm(Control control)
{ }