我的数据网格有格式问题。我已应用格式设置属性aDataColumn.DataFormatString = "{0:d}"
Private Function CreateColumnFromNode(ByVal aDisplayPropertyNode As XmlNode) As BoundColumn
Dim PropertyKey As String = cXMLDoc.AttributeToString(aDisplayPropertyNode, "PropertyKey")
Dim ColumnHeader As String = ConfigurableText(cXMLDoc.AttributeToString(aDisplayPropertyNode, "ColumnHeader"))
If PropertyKey = "" Then Return Nothing
Dim aDataColumn As New BoundColumn()
aDataColumn.DataField = PropertyKey
aDataColumn.HeaderText = IIf(ColumnHeader = "", PropertyKey, ColumnHeader)
<b> aDataColumn.DataFormatString = "{0:d}"</b>
Return aDataColumn
End Function
到数据网格。导出到excel时,它采用系统的默认设置。
我使用以下代码进行导出。不是自定义代码。
它使用asp.net proprty。
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.Charset = ""
' set the response mime type
response.ContentType = "application/vnd.ms-excel"
response.AddHeader("Content-Disposition", "attachment;filename=" + aFileName)
' create a string writer
Using sw As System.IO.StringWriter = New System.IO.StringWriter()
Using htw As HtmlTextWriter = New HtmlTextWriter(sw)
' instantiate a datagrid
DataGrid1.RenderControl(htw)
response.Write(sw.ToString())
End Using
End Using
response.End()
谢谢..
答案 0 :(得分:0)
我建议您在导出到Excel时获取默认系统设置的原因是Excel的自动单元格格式功能,它将查看单元格的值内容并自动应用其中一个预定义的格式化它,除非用户以其他方式指定特定格式来覆盖此格式。
由于我们无法看到您的Excel导出代码,我假设您自己正在执行此操作,在这种情况下,您需要在代码中添加一行以设置该列的日期时间格式,或者设置其格式到文本。要测试这个,请打开您已导出的电子表格之一,并将列格式更改为文本,然后查看它是否为您提供原始数据。