在excel的每列中显示数据库值

在excel的每列中显示数据库值,excel,vb.net,Excel,Vb.net,我想将我的数据库值提取到excel..因此我给出了如下代码: sql = "select * from tbl_ItemTransfer" cmd1 = New SqlCeCommand(sql, cn) dr = cmd1.ExecuteReader() ListBox1.Items.Add("Extracting " & strfilename) ListBox1.Refresh()

我想将我的数据库值提取到excel..因此我给出了如下代码:

 sql = "select * from  tbl_ItemTransfer"
            cmd1 = New SqlCeCommand(sql, cn)
            dr = cmd1.ExecuteReader()

            ListBox1.Items.Add("Extracting " & strfilename)
            ListBox1.Refresh()
            While (dr.Read())

                sw = New StreamWriter(hht_Storage & "\Export\" & strfilename & ".xls", True)
                prcount = 0
                fvalues = ""
                For I = 0 To dr.FieldCount - 1
                    If fvalues = "" Then
                        fvalues = IIf(IsDBNull(dr(I)), "", dr(I))
                        fvalues = Trim(Replace(fvalues, "'", ""))
                    Else
                        fvalues = fvalues & "|"
                        fvalues = fvalues & IIf(IsDBNull(dr(I)), "", dr(I))
                        fvalues = Trim(Replace(fvalues, "'", ""))
                    End If
                Next I

                sw.WriteLine(fvalues)
                prcount = prcount + 1
                sw.Close()
            End While
所以我所有的值都在一列中,以“|”分隔。我想在每一列中显示我所有的价值,而不是这个。我如何做到这一点?
任何帮助都非常有用。

使用
string.split
方法分割值

我将输出放入一个数组/数据表中,以便轻松地拆分行

然后可以将拆分值逐行写入excel工作表

希望这能让你更进一步