Wednesday, November 28, 2012

Creating an Excel file


1. In the AOT, create a new job named CreateExcelFile with the following code:

static void CreateExcelFile(Args _args)
{
    CustTable custTable;
    SysExcelApplication excel;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    SysExcelCell cell;
    int row;
    excel = SysExcelApplication::construct();
    workbooks = excel.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    cells.range('A:A').numberFormat('@');
    while select custTable
    {
        row++;
        cell = cells.item(row, 1);
        cell.value(custTable.AccountNum);
        cell = cells.item(row, 2);
        cell.value(custTable.name());
    }
    excel.visible(true);
}

2. Run the job and check the list of customers on the screen:


3. Save the list as a file for further use in the next recipe, say C:\temp\customers.xlsx.

No comments: