可可果

哈利是一只有白点的黑狗

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 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   }
posted on 2007-10-17 14:44  可可果  阅读(1485)  评论(0编辑  收藏  举报