看板 Web_Design 關於我們 聯絡資訊
我現在只有按下按鈕後,會匯出GridView裡全部的資料出來成Excel檔 我按查詢後,再匯出檔案...兩個檔案匯出的內容一樣 請問要怎麼修改,匯出的檔案內容是查詢後的資料 protected void btnOutput_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition","attachment;filename=Excel.xls"); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(tw); GridView1.AllowSorting = false; GridView1.AllowPaging = false; GridView1.Columns.RemoveAt(GridView1.Columns.Count - 1); GridView1.DataBind(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5"); HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=big5>"); HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=text/html;charset=big5></head>"); HttpContext.Current.Response.Charset = "big5"; HtmlForm hf = new HtmlForm(); Controls.Add(hf); hf.Controls.Add(GridView1); hf.RenderControl(htw); Response.Write(tw.ToString()); Response.End(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.34.225.114
shecolor: 大大您好,我都是用NPOI來處理Excel問題,覺得很穩定。 05/07 12:48