public void ExportToExcel(System.Web.UI.Control ctl)
{
bool CurrCtlVisible=ctl.Visible;
ctl.Visible=true; Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
ctl.Page.EnableViewState = true;
ctl.Visible=CurrCtlVisible;
}
{
bool CurrCtlVisible=ctl.Visible;
ctl.Visible=true; Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
ctl.Page.EnableViewState = true;
ctl.Visible=CurrCtlVisible;
}
浙公网安备 33010602011771号