[問題] datagrid export Excel 如何加匯出時間

看板C_Sharp作者 (左慈)時間15年前 (2010/05/29 08:11), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
大家好,我的匯出code是從網路上找來, 也可以將datagrid export to Excel, 但user希望在excel表的第一個row 顯示會出的資料名和匯出時間, 請問我如何才可以新增一個row放資料名和匯出時間? 我是用VS2003 c# private void toExcel_Click(object sender, System.Web.UI.ImageClickEventArgs e) { string attachment = "attachment; filename=Contacts.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); // Create a form to contain the grid HtmlForm frm = new HtmlForm(); dgService.Parent.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(dgService); frm.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.130.128

05/29 10:23, , 1F
你如何把資料塞入Excel?
05/29 10:23, 1F

05/29 13:32, , 2F
user在aspx會看到dgService這個datagrid,然後直接匯出
05/29 13:32, 2F

05/29 13:32, , 3F
excel表
05/29 13:32, 3F

05/29 13:42, , 4F
如果user要在excel裡多加一欄,你就不能用原本的寫法...
05/29 13:42, 4F

05/29 14:33, , 5F
那請問一下該用哪種方式??
05/29 14:33, 5F
文章代碼(AID): #1C05kpOv (C_Sharp)