(placeholder)

Do You Speak Excel?

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

// Excel OleAutoClient Example

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

// Call oleAutoclient - allocate objekt oExcel

oExcel=new oleAutoclient('excel.application')


// Create empty Workbook

oExcel.workbooks.add()


// Example: Put a text in Cell 1,1

// Allocate the Cell object

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

// Important put single quote in front of values to ensure that excel  

// does not make stupid reformatting assumptions

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


// Make Excel visible

oExcel.visible=true


// Fill the second cell

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

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


// Change column width

ocell.columnWidth := 25


// Put data into 3 and 4th cells

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

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

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

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


// Example define a range of cells

cRange = "C1:D1"  

oExcel.Range( cRange ).select()

// Change the background colour

oExcel.Selection.Interior.ColorIndex := 40


// Insert a title

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

oExcel.Selection.Insert()

// Alternative method setting values

// Use cell designator A1 instead of 1,1

//

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 knows 56 colours

nRow = 3

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

  nRow += 1

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

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

  oCell.Interior.ColorIndex := i

next


// Store the results

cname="MyFile.xls"

if file(cname)

  erase(cname)

endif

// Switch off warnings

oExcel.displayAlerts := false


// Store results

oExcel.activeWorkbook.saveAs(cname)


// Close the workbook

// and close Excel

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

  oExcel.activeWorkbook.close()

  oExcel.workbooks.close()

  oExcel.visible=false

  oExcel.Quit()

  release object oExcel    

endif