Hallo zusammen,
ich versuche den Inhalt eines DataGridView damit in eine ANSI-Textdatei zu exportieren:
[highlight=vbnet]
Private Sub AllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllToolStripMenuItem.Click
Dim w As IO.StreamWriter
Dim i As Integer
Dim col As Integer
Dim saveGrid As System.Windows.Forms.SaveFileDialog
saveGrid = New System.Windows.Forms.SaveFileDialog()
saveGrid.Filter = "CSV (*.csv) |*.csv|(*.unl) |*.unl|(*.*) |*.*"
saveGrid.AddExtension = True
Dim sf As String
Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(28591)
sf = saveGrid.FileName
If saveGrid.ShowDialog() = Windows.Forms.DialogResult.OK Then
w = New IO.StreamWriter(saveGrid.FileName)
For i = 0 To Me.grid1.Columns.Count - 1
w.Write("""" & Me.grid1.Columns.Item(i).HeaderText & """", enc)
If i < Me.grid1.Columns.Count - 1 Then
w.Write("|", enc)
End If
Next i
w.Write(w.NewLine, enc)
For i = 0 To Me.grid1.Rows.Count - 1
For col = 0 To Me.grid1.Columns.Count - 1
w.Write("""" & Trim(Me.grid1.Rows.Item(i).Cells.Item(col).Value.T oString & """"))
If col < Me.grid1.Columns.Count - 1 Then
w.Write("|", enc)
End If
Next col
w.Write(w.NewLine, enc)
Next i
w.Close()
End If
End Sub
[/highlight]
Allerdings ist die Ausgabedatei immernoch UTF-8 codiert. Wo muss in diesem Fall System.Text.Encoding.GetEncoding(28591) korrekt platziert werden, damit die Daten in ANSI in die Datei geschrieben werden bzw. wo liegt da mein Fehler?
ich versuche den Inhalt eines DataGridView damit in eine ANSI-Textdatei zu exportieren:
[highlight=vbnet]
Private Sub AllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllToolStripMenuItem.Click
Dim w As IO.StreamWriter
Dim i As Integer
Dim col As Integer
Dim saveGrid As System.Windows.Forms.SaveFileDialog
saveGrid = New System.Windows.Forms.SaveFileDialog()
saveGrid.Filter = "CSV (*.csv) |*.csv|(*.unl) |*.unl|(*.*) |*.*"
saveGrid.AddExtension = True
Dim sf As String
Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(28591)
sf = saveGrid.FileName
If saveGrid.ShowDialog() = Windows.Forms.DialogResult.OK Then
w = New IO.StreamWriter(saveGrid.FileName)
For i = 0 To Me.grid1.Columns.Count - 1
w.Write("""" & Me.grid1.Columns.Item(i).HeaderText & """", enc)
If i < Me.grid1.Columns.Count - 1 Then
w.Write("|", enc)
End If
Next i
w.Write(w.NewLine, enc)
For i = 0 To Me.grid1.Rows.Count - 1
For col = 0 To Me.grid1.Columns.Count - 1
w.Write("""" & Trim(Me.grid1.Rows.Item(i).Cells.Item(col).Value.T oString & """"))
If col < Me.grid1.Columns.Count - 1 Then
w.Write("|", enc)
End If
Next col
w.Write(w.NewLine, enc)
Next i
w.Close()
End If
End Sub
[/highlight]
Allerdings ist die Ausgabedatei immernoch UTF-8 codiert. Wo muss in diesem Fall System.Text.Encoding.GetEncoding(28591) korrekt platziert werden, damit die Daten in ANSI in die Datei geschrieben werden bzw. wo liegt da mein Fehler?
Comment