DevTrain Startseite Visual Studio 1 Magazin  
  
  
SUCHEN:  
ARTIKEL ONLINE: 525   

Kategorien
.NET
Datenbanken
Web
XML

Allgemein
Camp
Foren
Events
Persönliche Einstellungen
Registrieren
Prämien Shop
Kontakt
Impressum
Über DevTrain

Autoren



 

Forum: VB.NET | Thema: Re: Werte von VB.net nach Excel übertragen | Von: Tobi Ulm ( 13.07.2004 14:10)

Hi ?,

hier ein bischen Code (musst dazu aber wie Klaas geschrieben hat eine COM Referenz auf Office machen)
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
' An Excel spreadsheet involves a hierarchy of objects, from
' Application to Workbook to Worksheet.
Dim excelApp As New Excel.Application()
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = _
CType(excelBook.Worksheets(1), Excel.Worksheet)

' Unlike the Word demo, we'll make the spreadsheet visible so you can
' see the data being entered.
excelApp.Visible = True

' Set the column headers and desired formatting for the
' spreadsheet.
Dim rng As Excel.Range = excelWorksheet.Range("A1")
With rng
.ColumnWidth = 21.71
.Value = "Item"
.Font.Bold = True
End With

rng = excelWorksheet.Range("B1")
With rng
.ColumnWidth = 9
.HorizontalAlignment = Excel.Constants.xlRight
.Font.Bold = True
.Value = "Price"
End With

rng = excelWorksheet.Range("C1")
With rng
.ColumnWidth = 9
.HorizontalAlignment = Excel.Constants.xlRight
.Font.Bold = True
.Value = "Calories"
End With

' Start the counter on the second row of the worksheet, following the
' column headers.
Dim i As Integer = 2

' Loop through the Rows collection of the DataSet and write the data in
' each row to the cells in Excel.
With excelWorksheet
Dim dr As DataRow
For Each dr In dsMenu.Tables(0).Rows
.Range("A" & i.ToString).Value = dr("Item")
.Range("B" & i.ToString).Value = dr("Price")
.Range("C" & i.ToString).Value = dr("Calories")
i += 1
Next
End With

rng = excelWorksheet.Range("A8:C8")
With rng
.Font.Color = RGB(255, 0, 0)
.Font.Bold = True
.Range("A1").Value = "Average Calories"
End With

End Sub

cu

Tobi

cu

Tobi


Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!

 Betreff:
 Nachricht: Den Beitrag finden Sie nun unter: http://beta.devtrain.de/foren Die Benutzerdaten und Foreninhalte von beta.devtrain.de und www.devtrain.de sind die selben.
Sie können sich dort sogar per RSS über neue Inhalte informieren lassen.
Bei Problemen bitte direkt Mail an asp [AT] ppedv.de.

 Signatur:

  



Login
Username:


Passwort:






Passwort vergessen?

Visual Studio 1 Magazin

© Copyright 2003 ppedv AG