siye1982
 1 public void OutPutExcel()
 
2   {
 
3    //定义文档类型、字符编码
 4    Response.Clear();
 
5           Response.Buffer= true;
 
6           Response.Charset="GB2312";
 
7    string Name=ReprotName(Request.QueryString["id"],HotelID);
 
8 
 
9    //下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开
10           //filename=FileReport.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc    .xls    .txt   .htm
11    //System.Text.Encoding.GetEncoding("utf-8").GetEncoder
12 //解决了导出文件名乱码的问题
13           Response.AppendHeader("Content-Disposition","attachment;filename="+System.Web.HttpUtility.UrlEncode(Name,System.Text.Encoding.UTF8)+".xls");
14           Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");
15           //Response.ContentType指定文件类型可以为application/ms-excel、application/ms-word、application/ms-txt、 application/ms-html 或其他浏览器可直接支持文档
16           Response.ContentType = "application/ms-excel";
17          this.plContainer.EnableViewState = false;
18    // 定义一个输入流
19 
20     System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
21     System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
22    
23    plContainer.RenderControl(oHtmlTextWriter);
24    
25           //this 表示输出本页,你也可以绑定datagrid,或其他支持obj.RenderControl()属性的控件
26           Response.Write(oStringWriter.ToString());
27           Response.End();
28   }

分类:

技术点:

相关文章:

  • 2021-07-16
  • 2021-08-20
  • 2021-09-28
  • 2021-10-15
  • 2022-01-15
  • 2021-05-19
  • 2021-12-02
  • 2021-10-09
猜你喜欢
  • 2021-10-17
  • 2021-11-14
  • 2021-11-24
  • 2021-08-31
  • 2021-09-07
  • 2021-04-15
  • 2021-10-02
相关资源
相似解决方案