我正在使用 asp.net Web 应用程序中的响应对象创建一个 excel 文件。一些长数值正在转换为科学计数法。我想保留我正在使用的代码,因为它可以防止由于数据大小而收到的超时问题。有人可以就如何修改现有代码以防止列转换为科学计数法提供任何建议吗?
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=test.csv")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Try
sqlconn.Open()
Dim dr As SqlDataReader = sqlcmd.ExecuteReader()
Dim sb As New StringBuilder()
'Add Header
For count As Integer = 0 To dr.FieldCount - 1
If dr.GetName(count) IsNot Nothing Then
sb.Append(dr.GetName(count))
End If
If count < dr.FieldCount - 1 Then
sb.Append(",")
End If
Next
Response.Write(sb.ToString() & vbLf)
Response.Flush()
'Append Data
While dr.Read()
sb = New StringBuilder()
For col As Integer = 0 To dr.FieldCount - 2
If Not dr.IsDBNull(col) Then
sb.Append(dr.GetValue(col).ToString().Replace(",", " "))
End If
sb.Append(",")
Next
If Not dr.IsDBNull(dr.FieldCount - 1) Then
sb.Append(dr.GetValue(dr.FieldCount - 1).ToString().Replace(",", " "))
End If
Response.Write(sb.ToString() & vbLf)
Response.Flush()
End While
dr.Dispose()
Catch ex As Exception
Finally
sqlconn.Close()
End Try
Response.End()