Search This Blog

Tuesday, 6 December 2011

Import Data in Excel


Make a new project with the following class.
class SDExcelExport{}
public static void main(Args args)
{

    CustTable custTable;
    SysExcelApplication application;
    SysExcelWorkBooks    workbooks;
    SysExcelWorkBook     workbook;
    SysExcelWorksheets  worksheets;
    sysExcelWorksheet   worksheet;
    SysExcelCells       cells;
    SysExcelCell        cell;
    int                 row;

    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks(); //gets the workbook object
    workbook = workbooks.add();  // creates a new workbook
    worksheets = workbook.worksheets(); //gets the worksheets object
    //The following selects the first worksheet in the workbook to insert data
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    // numberFormat ‘@’ is to insert data as Text

    cells.range('A:A').numberFormat('@');
    while select custTable
    //The following loop will provide the data to be populated in each column
    {
        row++;
        cell = cells.item(row,1);
        cell.value(custTable.AccountNum);
        cell = cells.item(row,2);
        cell.value(custTable.Name);
        cell = cells.item(row,3);
        cell.value(CustTable.CustGroup);
        cell = cells.item(row,4);
        cell.value(CustTable.Currency);
        cell = cells.item(row,5);
        cell.value(CustTable.CreditMax);
        cell = cells.item(row,6);
        cell.value(CustTable.CreditRating);
    }
    application.visible(true);  '// opens the excel worksheet
}

No comments:

Post a Comment