/// <summary>
/// 导出显示数据Execl
/// </summary>
/// <param name="ctl">控件ID</param>
public void Excel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset = "gb2312";//UTF-8
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
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);
string ss = "<meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/" />";//加入编码
string DC = ss+tw.ToString();
HttpContext.Current.Response.Write(DC);
HttpContext.Current.Response.End();
}
导出显示数据的Execl
最新推荐文章于 2024-10-04 17:52:38 发布