Sub Button_Click(ByVal filename As String, ByVal GV As Object)
HttpContext.Current.Response.Clear()
Dim style As String = "<style> .text { mso-number-format:\@; } </style> " 'CSS style
HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=UTF-8>")
HttpContext.Current.Response.AppendHeader("content-disposition", "attachment;filename=" & HttpContext.Current.Server.UrlEncode(filename))
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
GV.EnableViewState = False
GV.AllowPaging = False
GV.AllowSorting = False
GV.DataBind()
Dim objStringWriter As System.IO.StringWriter = New System.IO.StringWriter()
Dim objHtmlTextWriter As HtmlTextWriter = New HtmlTextWriter(objStringWriter)
GV.RenderControl(objHtmlTextWriter)
HttpContext.Current.Response.Write(style)
HttpContext.Current.Response.Write(objStringWriter.ToString())
HttpContext.Current.Response.End()
HttpContext.Current.Response.Close()
GV.AllowPaging = True
GV.AllowSorting = True
GV.DataBind()
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中
End Sub
Protected Sub DETAILVIEW_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles DETAILVIEW.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Cells(3).Attributes.Add("class", "text")
e.Row.Cells(7).Attributes.Add("class", "text")
e.Row.Cells(8).Attributes.Add("class", "text")
e.Row.Cells(9).Attributes.Add("class", "text")
End If
End Sub
mso-number-format:"0\.00" 2 Decimals
mso-number-format:"mm\/dd\/yy" Date format
mso-number-format:"m\/d\/yy\ h\:mm\ AM\/PM" D -T AMPM
mso-number-format:"Short Date" 05/06/-2008
mso-number-format:"Medium Date" 05-jan-2008
mso-number-format:"Short Time" 8:67
mso-number-format:"Medium Time" 8:67 am
mso-number-format:"Long Time" 8:67:25:00
mso-number-format:"Percent" Percent - two decimals
mso-number-format:"0\.E+00" Scientific Notation
mso-number-format:"\@" Text
mso-number-format:"\#\ ???\/???" Fractions - up to 3 digits (312/943)
mso-number-format:"\0022£\0022\#\,\#\#0\.00" £12.76
mso-number-format:"\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ " 2 decimals, negative numbers in red and signed