D
Dan
Hi,
i want to export text from fields in a table to an excel sheet.
This code below works. The problem is that when a field contains text with
'return' in it, the text is put in 2 (or more) rows in excel instead of one
row.
Is there a way to solve this, e.g. by removing the 'returns' (but how)
before sending the text to excel, or ...
Thanks for help
Dan.
Dim objFileStream As FileStream
Dim objStreamWriter As StreamWriter
objFileStream = New FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Write)
objStreamWriter = New StreamWriter(objFileStream)
connection.Open()
Dim sql As String = "SELECT * FROM mytable"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
dr = cmd.ExecuteReader()
While dr.Read()
For i = 1 To dr.FieldCount - 1
strLine = strLine & dr.GetValue(i) & Chr(9)
Next
objStreamWriter.WriteLine(strLine)
strLine = ""
End While
dr.Close()
connection.Close()
objStreamWriter.Close()
objFileStream.Close()
i want to export text from fields in a table to an excel sheet.
This code below works. The problem is that when a field contains text with
'return' in it, the text is put in 2 (or more) rows in excel instead of one
row.
Is there a way to solve this, e.g. by removing the 'returns' (but how)
before sending the text to excel, or ...
Thanks for help
Dan.
Dim objFileStream As FileStream
Dim objStreamWriter As StreamWriter
objFileStream = New FileStream(fileName, FileMode.OpenOrCreate,
FileAccess.Write)
objStreamWriter = New StreamWriter(objFileStream)
connection.Open()
Dim sql As String = "SELECT * FROM mytable"
Dim cmd As SqlCommand = New SqlCommand(sql, connection)
dr = cmd.ExecuteReader()
While dr.Read()
For i = 1 To dr.FieldCount - 1
strLine = strLine & dr.GetValue(i) & Chr(9)
Next
objStreamWriter.WriteLine(strLine)
strLine = ""
End While
dr.Close()
connection.Close()
objStreamWriter.Close()
objFileStream.Close()