Hi,
ich exportiere Daten aus einer DGV nach Excel. Das funktioniert auch wunderbar. Jetzt möchte ich die Excel aber noch als Tabelle formatieren. Hier scheitert leider jeglicher Versuch.
Hier mein Code.
Wenn ich bei Excel den Macrorecorder laufen lasse, erhalte ich folgendes:
Ich weiß nun aber nicht wie ich das umsetzen kann
Vielleicht könnt ihr mir ja weiterhelfen
*Topic verschoben*
ich exportiere Daten aus einer DGV nach Excel. Das funktioniert auch wunderbar. Jetzt möchte ich die Excel aber noch als Tabelle formatieren. Hier scheitert leider jeglicher Versuch.
Hier mein Code.
VB.NET-Quellcode
- Dim oExcel As Object
- Dim oBook As Object
- Dim oSheet As Object
- Try
- oExcel = CreateObject("Excel.Application")
- oBook = oExcel.Workbooks.Add
- oSheet = oBook.Worksheets(1)
- oSheet.Cells(1, 1) = "NAME"
- oSheet.Cells(1, 2) = NUMMER
- For i = 0 To DataGridView1.RowCount - 1
- oSheet.Cells(i + 2, 1).NumberFormat = "@"
- Try
- oSheet.Cells(i + 2, 1) = DataGridView1(0, i).Value.ToString()
- oSheet.Cells(i + 2, 2) = DataGridView1(1, i).Value.ToString()
- Catch ex As Exception
- End Try
- Next
- oSheet.Columns("A:Z").AutoFit
- Dim password As String = "Test"
- oBook.Password = password
- oBook.SaveAs(ExcelExportPfad, password:=password)
- oSheet = Nothing
- oBook.Close()
- oBook = Nothing
- oExcel.Quit()
- oExcel = Nothing
Wenn ich bei Excel den Macrorecorder laufen lasse, erhalte ich folgendes:
Ich weiß nun aber nicht wie ich das umsetzen kann
Vielleicht könnt ihr mir ja weiterhelfen
*Topic verschoben*
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()