/// <summary>
///
/// </summary>
/// <param name="dg"></param>
/// <param name="name"></param>
/// <param name="bm">编码</param>
public static void OutExcel(System.Web.UI.Control dg, string name, string bm)
{
HttpResponse rsp = HttpContext.Current.Response;
dg.Visible = true;
rsp.Clear();
rsp.Buffer = true;
rsp.Charset = bm;
name = "attachment;filename=" +HttpUtility.UrlPathEncode(name)+".xls";
rsp.AppendHeader("Content-Disposition", name);
rsp.ContentEncoding = System.Text.Encoding.GetEncoding(bm);
rsp.ContentType = "application/ms-excel";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Page page = new Page();
page.EnableEventValidation = false;
page.DesignerInitialize();
HtmlForm form = new HtmlForm();
page.Controls.Add(form);
form.Controls.Add(dg);
page.RenderControl(oHtmlTextWriter);
rsp.Write(oStringWriter.ToString());
rsp.End();
}
public static void OutWord(System.Web.UI.WebControls.WebControl dg, string name)
{
HttpResponse rsp = HttpContext.Current.Response;
dg.Visible = true;
rsp.Clear();
rsp.Buffer = true;
rsp.Charset = "utf-8";
name = "attachment;filename=" + name;
rsp.AppendHeader("Content-Disposition", name);
rsp.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
rsp.ContentType = "application/ms-word";
dg.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Page page = new Page();
page.EnableEventValidation = false;
page.DesignerInitialize();
HtmlForm form = new HtmlForm();
page.Controls.Add(form);
form.Controls.Add(dg);
form.RenderControl(oHtmlTextWriter);
rsp.Write(oStringWriter.ToString());
rsp.End();
}