GridView匯出轉成Excel 可以下面的code就可以匯出excel Protected Sub BtnExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnExcel.Click Dim strExportFilename As String = "ExportedData" Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=" + strExportFilename + ".xls") Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls" Response.Charset = "big5" Dim stringWrite As New System.IO.StringWriter Dim htmlWrite As New HtmlTextWriter(stringWrite) GridView1.RenderControl(htmlWrite) Response.Write(stringWrite.ToString().Replace("<div>", "").Replace("</div>", "")) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) ' 解決Error:型別 'GridView' 的控制項 'GridView1' 必須置於有 runat=server 的表單標記之中。 End Sub ...