To protect your privacy we neither store cookies nor use any google add-ons such as google analytics.

Do You Speak Excel?

//////////////////////////////////////////

// Beispiel Excel OleAutoClient

//////////////////////////////////////////

// Aufruf oleAutoclient - zuweisen objekt oExcel

oExcel=new oleAutoclient('excel.application')


// Leeres Workbook hinzufügen

oExcel.workbooks.add()


// Beispiel: zuweisen Text in Zelle 1,1

// Objekt oCell wird zugewiesen

oCell=oExcel.activeSheet.cells(1,1)


// WICHTIG Hochkomma vorausstellen damit Excel die Werte 

// nicht eigenständig interpretiert

oCell.formula := [']+"Text 1"


// Excel sichtbar machen

oExcel.visible=true


// 2. Zelle versorgen

oCell=oExcel.activeSheet.cells(1,2)

oCell.formula := [']+"text2 in cell 2"


// Spaltenbreite ändern

ocell.columnWidth := 25


// 3. und 4.  Zelle mit variable Daten versorgen

oCell=oExcel.activeSheet.cells(1,3)

oCell.formula := [']+dtoc(date())

oCell=oExcel.activeSheet.cells(1,4)

oCell.formula := [']+time()


// Beispiel Zellenbereich definieren

cRange = "C1:D1" 

oExcel.Range( cRange ).select()


// Hintergrundfarbe verändern

oExcel.Selection.Interior.ColorIndex := 40


// Titel Zeile nachträglich einfügen

oExcel.Rows("1:1").Select()

oExcel.Selection.Insert()

// Alternativmethode Werte zuweisen

// Hier wird Zellenbezeichnung A1 anstelle 1,1

// verwendet

oExcel.Range("A1").Select()

with ( oExcel.ActiveCell )

   Formula := ['] +"Titel"+" "+dtoc(date())

   font.name := "Times New Roman"

   font.size := 10

   font.bold := true

   Interior.ColorIndex := 53

   Font.ColorIndex := 2

endwith


// Excel kennt 56 Farben

nRow = 3

for i=1 to 56 // excel has 56 colors

  nRow += 1

  oCell=oExcel.activeSheet.cells(nRow,1)

  oCell.Formula := ['Color ]+ltrim(str(i))

  oCell.Interior.ColorIndex := i

next


// Egebnis abspeichern

cname="MeinDatei.xls"

if file(cname)

  erase(cname)

endif


// Warnhinweise ausschalten

oExcel.displayAlerts := false


// Ergebis speichern

oExcel.activeWorkbook.saveAs(cname)


// Falls erforderlich workbook schliessen

// und Excel beenden

if msgbox("Excel Schliessen","Hinweis",20) = 6

  oExcel.activeWorkbook.close()

  oExcel.workbooks.close()

  oExcel.visible=false

  oExcel.Quit()

  release object oExcel   

endif