[問題] 匯出Excel當作資料來源

看板C_Sharp作者 (迴圈)時間14年前 (2010/03/01 23:24), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
寫了下列方式將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

03/02 00:30, , 1F
要不要考慮用NPOI輸出excel?
03/02 00:30, 1F


03/02 23:56, , 3F
感謝!
03/02 23:56, 3F
文章代碼(AID): #1BYznApT (C_Sharp)