Visual Basic Excel-Mappe erstellen

EuroCent

Klappstuhl 2.0
Guten Abend,

kann mir jemald erklären wie Ich in Visual Basic eine Excel-Mappe anlegen kann?

Folgendes möchte Ich machen,

via Button "Export in Excel" möchte Ich Daten in die Mappe einfügen.
Hier möchte Ich eine Zeile von Beispielsweise A1 - A3, mittig, gerahmt, Font-Size auf 18, Bold, Color und BackgroundColor ändern oder gar angeben

Danach soll Zeile für Zeile daten eingeflegt werden.

Tabellenblatt Name: "Produkte"

[LEERFELD][Produkt 1][Produkt 2][Produkt 3][Ziel][Fehlt]
[Monat]
[ KW00]
[ 1 ][ 0 ][ 0 ][ 1 ][ 0 ]
[ KW00][ 0 ][ 2 ][ 0 ][ 3 ][ 1 ]
[ KW00][ 0 ][ 0 ][ 4 ][ 7 ][ 3 ]
[ KW00][ 0 ][ 4 ][ 0 ][ 4 ][ 0 ]
[Monat]
[ KW00]
[ 5 ][ 0 ][ 0 ][ 5 ][ 0 ]
[ KW00][ 0 ][ 2 ][ 0 ][ 4 ][ 2 ]
[ KW00][ 0 ][ 0 ][ 3 ][ 5 ][ 2 ]
[Auswertung]
[Gesamt][ 6 ][ 8 ][ 7 ][ 29 ][ 8 ]
[Ziel ][ 0 ][ 0 ][ 0 ][ 37 ][LEERFELD]

etc...

Nun ist auch die Frage wie bekomme Ich dort dann noch eine Rohtabelle "Rohdaten" rein die dann die Werte hat wie:

[ DATUM ][ NUMMER ][ KATEGORIE ]
[ 00.00.0000 ][ 123456789 ][ Produkt A ]
[ 00.00.0000 ][ 123456789 ][ Produkt 3 ]
[ 00.00.0000 ][ 123456789 ][ Produkt B ]
etc...

PS: Die Daten werden vom Benutzer selbst in das Tool eingetragen, zum Auswerten klicken Sie dann auf "Export in Excel" und die Datei wird erstellt und versendet.

So hab ich mir das gedacht, alleridngs versuch Ich schon vergebens mit

Code:
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()

        If xlApp Is Nothing Then
            MsgBox("Excel is not properly installed!!")
            Return
        End If

        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet

        Dim misValue As Object = System.Reflection.Missing.Value

        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")
        xlWorkSheet.Cells(1, 1) = "Sheet 1 content"

        xlWorkBook.SaveAs("d:\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, _

         Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue)

        xlWorkBook.Close(True, misValue, misValue)

        xlApp.Quit()

        releaseObject(xlWorkSheet)
        releaseObject(xlWorkBook)
        releaseObject(xlApp)

        MsgBox("Excel file created , you can find the file d:\csharp-Excel.xls")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try         System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

End Class

Allerdings bekomm ich immer einen Fehler ausgeworfen :/

Ich hoffe mir kann hier einer Behilflich sein :)
 

Neue Beiträge

Zurück