看板 C_Sharp 關於我們 聯絡資訊
寫了下列方式將GridView匯出成Excel檔.. 匯出的Excel可以正常的用Excel 2003開啟 但是若要以此檔當作是另一個網頁的Source DB時,卻會有問題(格式問題) 所以我只好暫時將這個匯出的Excel檔另存新檔,再以此檔當作Source DB 請問該怎麼匯出,Excel格式才是正確的? protected void Button_ExportExcel_Click(object sender, EventArgs e) { Button BTN = sender as Button; GridView myGridView = BTN.FindControl("GridView1") as GridView; Response.Clear(); Response.AddHeader("content-disposition","attachment;filename=Export.xls"); Response.Charset = "BIG5"; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw); myGridView.AllowSorting = false; myGridView.AllowPaging = false; HtmlForm hf = new HtmlForm(); Controls.Add(hf); hf.Controls.Add(myGridView); hf.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.225.163.206
kinwind:要不要考慮用NPOI輸出excel? 03/02 00:30
whileloop:感謝! 03/02 23:56