Uellaaa buon anno a tutti!
Sto usando la sub che segue per generare un csv da un datatable:
Farebbe tutto quello che serve tranne che non mi tiene i punti come separatori decimali di alcuni numeri presenti in una colonna del datatable...codice:Public Shared Function WriteRiga(ByVal input As String) As String Try If (input Is Nothing) Then Return String.Empty End If Dim containsQuote As Boolean = False Dim containsComma As Boolean = False Dim len As Integer = input.Length Dim i As Integer = 0 Do While ((i < len) _ AndAlso ((containsComma = False) _ OrElse (containsQuote = False))) Dim ch As Char = input(i) If (ch = Microsoft.VisualBasic.ChrW(34)) Then containsQuote = True ElseIf (ch = Microsoft.VisualBasic.ChrW(44)) Then containsComma = True End If i = (i + 1) Loop If (containsQuote AndAlso containsComma) Then input = input.Replace(Microsoft.VisualBasic.ChrW(44), ".") input = input.Replace(Microsoft.VisualBasic.ChrW(34), "") Else Return input End If Catch ex As System.Exception 'Throw End Try End Function ..... Public sub FammiStoFileCSV() Dim filefisico As String = "C:\esportato.csv" Dim nomefile As String = "eccolo.csv" Dim filefisico As String = "C:/cartella/" & nomefile Dim dt As DataTable = GetCSVData() Dim sb As StringBuilder = New StringBuilder For Each dr As DataRow In dt.Rows For Each dc As DataColumn In dt.Columns sb.Append((WriteRiga(dr(dc.ColumnName)) + ",")) Next sb.Remove((sb.Length - 1), 1) sb.AppendLine() Next File.WriteAllText(filefisico, sb.tostring) 'redirect a downloader response.redirect("/dloader.ashx?lnk=" & nomefile) End sub
... helpz?
PS confesso che ne ho trovato in rete la gran parte e non sono così convinto che mi serva tutta quella funzione writeriga per fare il replace dei doppi apici e delle virgole... anyway...

Rispondi quotando