Created
December 15, 2016 18:13
-
-
Save Laicure/c88c15cccb88b502a2ecdf0e5e88695b to your computer and use it in GitHub Desktop.
Late Bind Export to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Region "Excel Export (StreamWriter; CSV file)" | |
'www.codeproject.com/Articles/26303/Export-Data-to-ex-Much-Faster | |
Friend Sub CreateExcelX(ByVal FilePath As String, ByVal datatabler As Data.DataTable) | |
Dim writer As New IO.StreamWriter(FilePath) | |
Dim dRow As Data.DataRow = Nothing | |
Dim str As String = String.Empty | |
For i As Integer = 0 To datatabler.Columns.Count - 1 | |
str += datatabler.Columns.Item(i).Caption & "," | |
Next | |
str += vbCrLf | |
writer.Write(str) | |
writer.Flush() | |
For Each dRow In datatabler.Rows | |
str = "" | |
For col As Integer = 0 To datatabler.Columns.Count - 1 | |
Dim STR1 As String = "" | |
Dim c As Char = Chr(32) | |
Dim sep As Char = CChar(",") | |
Dim str2() As String = Nothing | |
str2 = dRow(col).ToString.Split(CChar(vbCrLf)) | |
For z As Integer = 0 To str2.Length - 1 | |
If DateTime.TryParse(str2(z), Nothing) Then | |
STR1 += TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(str2(z)), "UTC", "Pacific Standard Time").ToString.Replace(",", " ") | |
Else | |
STR1 += str2(z).Replace(vbCr, " ").Replace(vbLf, " ").Replace(System.Environment.NewLine, " ").Replace(vbFormFeed, " ").Replace(vbVerticalTab, " ").Replace(vbTab, " ").Replace(",", " ") | |
End If | |
Next | |
str += STR1 & sep | |
Next | |
str += vbNewLine | |
writer.Write(str) | |
writer.Flush() | |
Next | |
writer.Close() | |
End Sub | |
#End Region |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment