Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)Handles Button1.Click
End Sub
'先處理不必要出現的欄位...
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") 'excel
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.doc") 'word
Response.Charset = "big5"
Response.ContentType = "application/vnd.ms-excel" 'excel
Response.ContentType = "application/vnd.msword" 'word
GridView1.AllowPaging = False '處理分頁
GridView1.DataBind() '處理分頁
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
GridView1.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString)
Response.End()
GridView1.AllowPaging = True '處理分頁
GridView1.DataBind() '處理分頁
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'此段為必要End Sub
處理分頁
將gridview匯出excel,如果gridview有分頁的話則會發生錯誤
ASP.NET中Gridview中的內容導出到Excel
TIPS-Export GridView To Excel
GridView匯出成EXCEL檔的問題
若出現:
RegisterForEventValidation 只能在 Render(); 期間呼叫
在<%@ Page %>加入EnableEventValidation="false"
參考:
請問如何將GridView1內容存成excel
解決GridView使用RenderControl取得HTML出現的問題
請問如何將不同的GridView匯出到不同的EXCEL sheet中
Asp.net將DataGrid匯出到Excel裡的多個worksheet工作表內
出現PageRequestManagerParserErrorException
在UpdatePanel中加入PostBackTrigger,ControlID="ClickButton"
在apsx原始檔<%Page ... %>中,加入EnableEventValidation = "false" AutoEventWireup="true"
Y的筆記本: 在AJAX下,將GridView另存Excell問題
老外分享的Export GridView to Excel
HttpContext.Current.Response.Charset = "big5"; HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("big5"); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
沒有留言:
張貼留言