[ad_1]
I have a large text file that I have so far written code that reads the file.
The next thing I want to do is to export the file to excel.
I want to split the file into different sheets in the same excel based on the first 5 digit string of each line.
example of text file:
12345 test line 1
12345 test line 2
67890 test line 3
12345 test line 4
12345 test line 5
67890 test line 6
67890 test line 7
eg. Sheet one:
12345 test line 1
12345 test line 2
12345 test line 4
12345 test line 5
sheet two:
67890 test line 3
67890 test line 6
67890 test line 7
If anyone knows the best way to export to excel using asp.net vb please let me know
Dim fu As FileUpload = FileUpload1
If fu.HasFile Then
Using reader As New StreamReader(fu.FileContent)
Const blockSize As Integer = 4 * 1024
Dim buffer(blockSize - 1) As Char
Dim charCount As Integer
Dim builder As New StringBuilder
Do Until reader.EndOfStream
'Read the next 4KB of the file.
charCount = reader.ReadBlock(buffer, 0, blockSize)
builder.Clear()
builder.Append(buffer, 0, charCount)
If charCount = blockSize Then
'Read up to the next line break and append to the block just read.
builder.Append(reader.ReadLine())
End If
Dim textBlock = builder.ToString()
'Rpt1.DataSource = textBlock
'Rpt1.DataBind()
Loop
reader.Close()
End Using
[ad_2]