Microsoft Dynamics AX development

To export data to an excel file, we can use the SysExcelWorksheetHelper.
Here an example:

static void exportExcelFile(Args _args)
    SysExcelApplication     xlsApplication;
    SysExcelWorkBooks       xlsWorkBookCollection;
    SysExcelWorkBook        xlsWorkBook;
    SysExcelWorkSheets      xlsWorkSheetCollection;
    SysExcelWorkSheet       xlsWorkSheet;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelHelper          sysExcelHelper;
    VendRFQJour             vendRFQJour;
    int                     row = 1;
    str                     fileName;
    str                     worksheetName;
    Date                    deliveryDate;

    fileName    = "Path\\Test.xlsx";

    vendRFQJour = VendRFQJour::find("000103");

    worksheetName = "Worksheet name";
    sysExcelHelper = SysExcelHelper::construct();
    xlsWorkSheet = sysExcelHelper.addWorksheet(worksheetName);

    worksheetHelper = SysExcelWorksheetHelper::construct(xlsWorkSheet);

    worksheetHelper.addColumn(1, 'RFQ Id', Types::String);
    worksheetHelper.addColumn(2, 'Delivery date', Types::Date);

    worksheetHelper.setCellValue(1, row, 'RFQId');
    worksheetHelper.setCellValue(2, row, 'DeliveryDate');

    worksheetHelper.setCellValue(1, row, vendRFQJour.RFQId);
    worksheetHelper.setCellValue(2, row, vendRFQJour.DeliveryDate);


    info(strFmt("Creato file: %1", fileName));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: