The code sample below illustrates how you would use early binding to create an Excel object in an ATEasy program. In order for the code to work, the Microsoft Excel Object Library must be inserted into the ATEasy application under its Libraries submodule with the default name, Excel. The application references the information contained in the Excel object library, and the Excel object variables are declared as specific Excel types:
Variable |
Declared As Type: |
xlapp |
Excel.Application |
xlrange |
Excel.Range |
xlchart |
Excel.Chart |
Because these variables are declared as specific Excel types, the code that uses them runs more efficiently.
xlapp=CreateObject("Excel.Application")
xlapp.Visible=TRUE
xlapp.Caption="ATEasy Excel Demo Using COM"
xlapp.Workbooks.Add()
! prepare data
as={"US-West", "US-East", "US-Central", "Europe", "Israel"}
ad={2123300.00, 2323300.00, 1123300.00, 1523300.00, 1200000.00}
iSize=sizeof(as)/sizeof(as[0])
! fill cells
for i=1 to iSize
xlapp.Cells().Item(i, 1).Value = as[i-1]
xlapp.Cells().Item(i, 2).Value = ad[i-1]
next
! check if cells got the data
if xlapp.Cells().Item(1, 1).Value<>as[0]
TestStatus=FAIL
endif
! add a new workbook with a chart
xlapp.Workbooks.Add() ! add workbook for chart
xlapp.Windows.Arrange() ! cascade the two workbooks	
xlchart=xlapp.Charts.Add() ! add a chart to the workbook
xlrange=xlapp.Workbooks().Item(1).Sheets().Item(1).Range("A1:B5")
! get the range for the chart
xlchart.SetSourceData(xlrange)
! fill\plot the chart
! free the objects
xlrange=Nothing
xlchart=Nothing
xlapp=Nothing