- Response.Clear();
- Response.Buffer = true;
- HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=TicketVisaMoneyDetail.xls;");
- HttpContext.Current.Response.Charset = "UTF-8";
- HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(936);//936是專門處理中文字符集的
- HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
- System.IO.StringWriter tw = new System.IO.StringWriter();
- System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
- this.tblCallableMoney.Page.EnableViewState = false;//如果轉檔出來的table有分頁,要加此句
- this.Bind_tblCallableMoney();
- //當用了母版頁時,要加這一段
- HtmlForm frm = new HtmlForm();
- this.tblCallableMoney.Parent.Controls.Add(frm);
- frm.Attributes["runat"] = "server";
- frm.Controls.Add(this.lblTitle);//轉檔出來後的標題
- frm.Controls.Add(this.tblCallableMoney);
- frm.RenderControl(hw);
- HttpContext.Current.Response.Write(tw.ToString());
- HttpContext.Current.Response.End();