VB 表格导出Excel 自动处理‘0’的问题

前端之家收集整理的这篇文章主要介绍了VB 表格导出Excel 自动处理‘0’的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub dgEX_ItemDataBound(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgEX.ItemDataBound
''''给要处理列加样式;解决收据号导出是‘0’自动处理的问题
e.Item.Cells(0).Attributes.Add("style","vnd.ms-excel.numberformat:@")

End Sub


导出方法

Public Overloads Shared Sub OutToExcel1(ByVal dg As DataGrid,ByVal httpResponse As HttpResponse,ByVal httpPage As Page,ByVal fileName As String) httpResponse.Clear() httpResponse.Buffer = True httpResponse.Charset = "GB2312" httpResponse.AppendHeader("Content-Disposition","attachment;filename=" & fileName) httpResponse.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312") '设置输出流为简体中文 httpResponse.ContentType = "application/ms-excel" '设置输出文件类型为excel文件。 httpPage.EnableViewState = False Dim myCItrad As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("ZH-CN",True) Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter(myCItrad) Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) dg.RenderControl(oHtmlTextWriter) httpResponse.Write(oStringWriter.ToString()) httpResponse.End() End Sub

猜你在找的VB相关文章