Updated CSV export for RFC 4180
This commit is contained in:
+24
-18
@@ -1,8 +1,6 @@
|
|||||||
Imports GBM.My.Resources
|
Imports GBM.My.Resources
|
||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.Xml.Serialization
|
Imports System.Xml.Serialization
|
||||||
Imports System.Globalization
|
|
||||||
|
|
||||||
|
|
||||||
Public Class mgrSessions
|
Public Class mgrSessions
|
||||||
|
|
||||||
@@ -130,24 +128,38 @@ Public Class mgrSessions
|
|||||||
Return iRowCount
|
Return iRowCount
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Private Shared Function EscapeCSV(ByVal sItem As String) As String
|
||||||
|
Dim bEnclose As Boolean = False
|
||||||
|
|
||||||
|
If sItem.Contains("""") Then
|
||||||
|
sItem = sItem.Replace("""", """""")
|
||||||
|
bEnclose = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
If sItem.Contains(",") Then
|
||||||
|
bEnclose = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
If sItem.Contains(vbCrLf) Or sItem.Contains(vbCr) Or sItem.Contains(vbLf) Then
|
||||||
|
bEnclose = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
If bEnclose Then
|
||||||
|
sItem = """" & sItem & """"
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return sItem
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Shared Function ExportAsCSV(ByVal sLocation As String, ByVal bUnixTime As Boolean, ByVal bHeaders As Boolean, ByRef dg As DataGridView) As Boolean
|
Public Shared Function ExportAsCSV(ByVal sLocation As String, ByVal bUnixTime As Boolean, ByVal bHeaders As Boolean, ByRef dg As DataGridView) As Boolean
|
||||||
Dim oWriter As StreamWriter
|
Dim oWriter As StreamWriter
|
||||||
Dim sHeader As String
|
Dim sHeader As String
|
||||||
Dim sCurrentRow As String
|
Dim sCurrentRow As String
|
||||||
Dim dDecimal As Decimal
|
|
||||||
Dim oBannedColumns As New List(Of DataGridViewColumn)
|
Dim oBannedColumns As New List(Of DataGridViewColumn)
|
||||||
Dim oDecimalColumns As New List(Of DataGridViewColumn)
|
|
||||||
Dim oNfi As New NumberFormatInfo
|
|
||||||
|
|
||||||
'We want to force a specific decimal seperator when exporting CSV files due to certain regions using a comma.
|
|
||||||
oNfi.NumberDecimalSeparator = "."
|
|
||||||
|
|
||||||
Try
|
Try
|
||||||
oWriter = New StreamWriter(sLocation)
|
oWriter = New StreamWriter(sLocation)
|
||||||
|
|
||||||
'Set Decimal Columns
|
|
||||||
oDecimalColumns.Add(dg.Columns("Hours"))
|
|
||||||
|
|
||||||
'Set Ban Columns
|
'Set Ban Columns
|
||||||
oBannedColumns.Add(dg.Columns("MonitorID"))
|
oBannedColumns.Add(dg.Columns("MonitorID"))
|
||||||
|
|
||||||
@@ -177,13 +189,7 @@ Public Class mgrSessions
|
|||||||
sCurrentRow = String.Empty
|
sCurrentRow = String.Empty
|
||||||
For Each dgCell As DataGridViewCell In dgRow.Cells
|
For Each dgCell As DataGridViewCell In dgRow.Cells
|
||||||
If Not oBannedColumns.Contains(dg.Columns(dgCell.ColumnIndex)) Then
|
If Not oBannedColumns.Contains(dg.Columns(dgCell.ColumnIndex)) Then
|
||||||
If oDecimalColumns.Contains(dg.Columns(dgCell.ColumnIndex)) Then
|
sCurrentRow &= EscapeCSV(dgCell.Value.ToString) & ","
|
||||||
dDecimal = CDec(dgCell.Value)
|
|
||||||
sCurrentRow &= dDecimal.ToString(oNfi) & ","
|
|
||||||
Else
|
|
||||||
sCurrentRow &= dgCell.Value.ToString & ","
|
|
||||||
End If
|
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
sCurrentRow = sCurrentRow.TrimEnd(",")
|
sCurrentRow = sCurrentRow.TrimEnd(",")
|
||||||
|
|||||||
Reference in New Issue
Block a user