Example of Using an Imported ActiveX Automation Object

The following example shows a Workspace or JadeScript method using a Microsoft Excel automation library imported into JADE to load three Excel cells with data, draw a chart, and print the result.

chartExample();
vars
    xl     : ExcelApp;      // ActiveX automation subclass
    wrkSht : Worksheet;     // interface subclass of the IDispatch class
    sht    : I_Worksheet;   // interface subclass of the IDispatch class
    rng    : Range;         // interface subclass of the IDispatch class
    chrts  : Sheets;        // interface subclass of the IDispatch class
    chrt   : I_Chart;       // interface subclass of the IDispatch class
begin
    // Start Excel
    create xl;
    xl.createAutomationObject;
    xl.visible := true;                    // See what’s going on
    xl.workbooks.add(xl.XlWorksheet);      // Add Workbook (with one sheet)
    sht := xl.activeSheet.I_Worksheet;     // Get top sheet and fill cells
    sht.range("A1", null).putValue("One");
    sht.range("B1", null).putValue("Two");
    sht.range("C1", null).putValue("Three");
    sht.range("A2", null).putValue(10);
    sht.range("B2", null).putValue(5);
    sht.range("C2", null).putValue(3);
    rng := sht.range("A1", "C2");          // Select cells
    chrts := xl.charts;                    // Add a chart
    chrts.add(null, null, null, null);
    chrt := xl.activeChart;
    // Start chart wizard
    chrt.chartWizard(rng,                  // source
                     xl.Xl3DPie,           // gallery
                     7,                    // format
                     xl.XlRows,            // plotBy
                     1,                    // categoryLabels
                     0,                    // seriesLabels
                     2,                    // hasLegend
                     "Jade Example",       // title
                     null,                 // categoryTitle
                     null,                 // valueTitle
                     null);                // xtraTitle
    // Output chart
    chrt.printOut(null,                    // first page
                  null,                    // last page
                  null,                    // copies
                  null,                    // preview
                  null,                    // printer
                  null,                    // print to file
                  null);                   // collate
epilog
    if xl <> null then
        xl.activeWorkbook.saved := true;   // Don't ask to save!
        xl.quit;                           // Close down Excel
        delete xl;
    endif;
end;