3
我能夠在GridView中顯示日期字段值dd MMM yyyy(2015年10月29日)。導出到Excel後,日期字段值格式將更改爲:dd-MMM-yy(29-Oct-15)。我的代碼:如何以'dd MMM yyyy'格式在導出的Excel中顯示數據表的日期字段
Protected Sub btnExportData_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnExportData.ServerClick
Try
Dim str As String
str = HiddenFilterString.Value
Dim dtExportData As New DataTable
Dim dtTemp As New DataTable
Dim dg As New DataGrid
dtTemp = DirectCast(Session("dtSoHoManageSecretServerFoldersExportData"), DataTable)
dtExportData = dtTemp.Copy()
Dim dv As New DataView(dtExportData)
dg.DataSource = dv
dg.DataBind()
Dim sFileName As String = "ServerFolders.xls"
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.Buffer = True
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & sFileName)
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
Me.EnableViewState = False
Dim objSW As New System.IO.StringWriter
Dim objHTW As New HtmlTextWriter(objSW)
dg.HeaderStyle.Font.Bold = True
dg.RenderControl(objHTW)
HttpContext.Current.Response.Write(objSW.ToString())
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()
dtExportData = Nothing
dtTemp = Nothing
dg = Nothing
dv = Nothing
objSW = Nothing
objHTW = Nothing
Catch ex As Exception
ReportInternalError("btnExportData_Click", ex)
Throw
End Try
End Sub
是否可以在導出的Excel中保留相同格式的GridView?