private void HB_ToExecl_Click(object sender, System.EventArgs e)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType ="application/ms-excel";
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write("<head><meta http-equiv=/"Content-Type/" content=/"text/html; charset=utf-8/"></head><body>"+tw.ToString()+"</body>");
HttpContext.Current.Response.End();
}
导出Excel的简单方法,并可以解决乱码问题
最新推荐文章于 2020-07-29 14:26:30 发布