GridView 导出Excel
时间:2011-01-25 来源:TNTZWC
{
//base.VerifyRenderingInServerForm(control);
}
protected void btnExpExcel_Click(object sender, EventArgs e)
{
this.Response.Clear();
this.Response.AppendHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + "FileName.xls");
this.Response.Charset = "UTF8"; //输出的字符集
this.Response.ContentEncoding = System.Text.Encoding.UTF8; //编码类型
Response.ContentType = "application/vnd.ms-excel"; //输出Excel
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.gvData.RenderControl(hw);
this.Response.Write(tw.ToString());
this.Response.End();
}
相关阅读 更多 +