CSV文件中的SQL表在Excel中将NULL行显示为“”

时间:2014-10-16 12:26:45

标签: sql vb.net excel csv gridview

基本上,我在我的VB.NET gridview中显示一个SQL表,一旦它在我的gridview中,我就有一个按钮,将visual studio中的结果导出为CSV文件,CSV文件中的所有内容看起来都很好,除了SQL表中任何为NULL的单元格现在显示为:

  

我尝试使用以下代码在存储过程中解决此问题:

UPDATE EmailManagementTable
SET Excluded = ''
WHERE Excluded IS NULL

但即使使用此代码,我仍然会遇到同样的问题。

这是我的按钮代码,用于将gridview结果导出为CSV:

    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=gvtocsv.csv")
    Response.Charset = ""
    Response.ContentType = "application/text"
    Dim sBuilder As StringBuilder = New System.Text.StringBuilder()
    For index As Integer = 0 To GridView1.Columns.Count - 1
        sBuilder.Append(GridView1.Columns(index).HeaderText + ","c)
    Next
    sBuilder.Append(vbCr & vbLf)
    For i As Integer = 0 To GridView1.Rows.Count - 1
        For k As Integer = 0 To GridView1.HeaderRow.Cells.Count - 1
            sBuilder.Append(GridView1.Rows(i).Cells(k).Text.Replace(",", "") + ",")
        Next
        sBuilder.Append(vbCr & vbLf)
    Next
    Response.Output.Write(sBuilder.ToString())
    Response.Flush()
    Response.[End]()

我想知道我能否得到一些帮助?

提前谢谢

1 个答案:

答案 0 :(得分:1)

我解决了我的问题!

我在导出按钮中编辑了一些代码,这是代码:

    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=gvtocsv.csv")
    Response.Charset = ""
    Response.ContentType = "application/text"
    Dim sBuilder As StringBuilder = New System.Text.StringBuilder()
    For index As Integer = 0 To GridView1.Columns.Count - 1
        sBuilder.Append(GridView1.Columns(index).HeaderText + ","c)
    Next
    sBuilder.Append(vbCr & vbLf)
    For i As Integer = 0 To GridView1.Rows.Count - 1
        For k As Integer = 0 To GridView1.HeaderRow.Cells.Count - 1
            sBuilder.Append(GridView1.Rows(i).Cells(k).Text.Replace(",", "").Replace(" ", "") + ",")
        Next
        sBuilder.Append(vbCr & vbLf)
    Next
    Response.Output.Write(sBuilder.ToString())
    Response.Flush()
    Response.[End]()