Excel mit leerer Tabelle öffnen

jansens

Grünschnabel
Hallo,

ich soll aus meinem Programm heraus Daten in eine Exceltabelle exportieren. Mein Programm liesst bereits Excelblätter aus, das ist also kein Problem.
Was nicht funktioniert ist: ExcelApp.Open("Filename einer nicht existierenden Datei")
Ich kann vorhandene Exceldateien öffnen und verändern aber wie lege ich eine neue,leere an?

Wenn mir da jemand helfen könnte, wäre ich sehr dankbar.

Sven
 
Hi, ich habe das in VB so gemacht:

Dim exc_App As Excel.Application
exc_App = CreateObject("Excel.Application")

dann das Workbook und die Worksheets angehaben und am Ende

mexc_Workbook.SaveAs(s_SavePath)

Gruß

Lukas
 
So einfach ist das? Mich hatte immer irritiert, dass ich das Excel nicht angezeigt bekommen habe, auch mit windowstate maximise nicht.

Aber es klappt auch ihne das Dingen sehen zu können.

Danke
 
Du kannst auch Excel öffnen, hier ist meine Funktion, die ich dafür verwendet habe:

Code:
    Public Function lokExcel_Show(ByVal excApp As Excel.Application) As Boolean

        If Not excApp Is Nothing Then
            With excApp
                .Visible = True
                .UserControl = True
            End With
            'Objektverweis freigeben
            excApp = Nothing
        End If

    End Function
 
Hallo

Hier mein Code:
Code:
Dim xlApp As Excel.Application
        Dim xlMappe As Excel.Workbook
        Dim xlBlatt As Excel.Worksheet
        Dim xlZelle As Excel.Range

        Dim ds As New DataSet

        Dim i As Integer = 0
        Dim vardatum As Date
        Dim varmonat As Integer

        Dim varbeg As Date


        'excel
        xlApp = New Excel.Application
        xlApp = CreateObject("Excel.Application")
        xlApp.Visible = False
        xlMappe = xlApp.Workbooks.Open("C:\Statistik.xlsx")
        xlBlatt = xlMappe.Worksheets(1)
        xlZelle = xlBlatt.Range("A1")

        vardatum = Today()
        varmonat = vardatum.ToString("MM")

            varbeg = "01.01." & Year(Today())
            Dim da As New SqlDataAdapter("select * from patient where ueb_von='' and beh_ende < '" & varbeg & "' and month(geb_dat) = " & varmonat & " order by beh_ende", con)
            da.Fill(ds, "a")
        Dim tbl As DataTable = ds.Tables(0)

        For Each row As DataRow In tbl.Rows
            'geb im aktuellem monat
            xlZelle.Offset(i, 1).Value = row("pat_nr")
            xlZelle.Offset(i, 2).Value = row("vorname")
            xlZelle.Offset(i, 3).Value = row("famname")
            xlZelle.Offset(i, 4).Value = row("strasse")
            xlZelle.Offset(i, 5).Value = row("plz")
            xlZelle.Offset(i, 6).Value = row("ort")
            xlZelle.Offset(i, 7).Value = row("geb_dat")
            xlZelle.Offset(i, 8).Value = row("beh_ende")
            i += 1
        Next

        xlApp.Visible = True
        'xlApp.Quit()


        xlZelle = Nothing
        xlBlatt = Nothing
        xlMappe = Nothing
        xlApp = Nothing
        tbl = Nothing
        ds = Nothing

        con.Close()

Mein Problem ist, dass er nie den Inhalt des Excel Worksheet löscht bevor er dien euen Daten hineinkopiert. Hat wer eine Ahnung?

Bitte um Info
 

Neue Beiträge

Zurück