2009-10-03 如何將GridView的內容匯出成Excel? 2526 0 ASP.NET-GridView 摘要:如何將GridView的內容匯出成Excel? Dim style As String = "<style> .text { mso-number-format:\@; } </style> " Response.AppendHeader("Content-Disposition", "attachment; filename=excel.xls") Response.ContentType = "application/vnd.ms-excel" Dim sw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(sw) Response.Write("<meta http-equiv=Content-Type content=text/html;charset=utf-8>") GridView1.RenderControl(hw) Response.Write(style) Response.Write(sw.ToString()) Response.End() Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound e.Row.Cells(1).Attributes.Add("class", "text") 回首頁