Pages

Banner 468 x 60px

 

Thursday, June 23, 2022

Export Data AX to Excel

0 comments

 static void ExportDataGeneralJournal(Args _args)

{

    SysExcelApplication     xlsApplication;

    SysExcelWorkBooks       xlsWorkBookCollection;

    SysExcelWorkBook        xlsWorkBook;

    SysExcelWorkSheets      xlsWorkSheetCollection;

    SysExcelWorkSheet       xlsWorkSheet;

    SysExcelRange           xlsRange;


    GeneralJournalEntry         jourEntry;

    GeneralJournalAccountEntry  jourAccEntry;

    FromDate                    fromDate = mkDate(1,1,2018);

    ToDate                      toDate = mkDate(31,1,2018);


    int                     row = 1;

    str                     fileName;

    ;

    //Filename

    fileName = "Document\GeneralAccEntry.xlsx";

    //Initialize Excel instance

    xlsApplication           = SysExcelApplication::construct();

    //Open Excel document

    //xlsApplication.visible(true);

    //Create Excel WorkBook and WorkSheet

    xlsWorkBookCollection    = xlsApplication.workbooks();

    xlsWorkBook              = xlsWorkBookCollection.add();

    xlsWorkSheetCollection   = xlsWorkBook.worksheets();

    xlsWorkSheet             = xlsWorkSheetCollection.itemFromNum(1);


    //Excel columns captions

    xlsWorkSheet.cells().item(row,1).value("Date");

    xlsWorkSheet.cells().item(row,2).value("Voucher");

    xlsWorkSheet.cells().item(row,3).value("PostingType");

    xlsWorkSheet.cells().item(row,4).value("LedgerAccount");

    row++;


    while select jourEntry

        join jourAccEntry

        where jourEntry.RecId == jourAccEntry.GeneralJournalEntry

           && jourEntry.AccountingDate >= fromDate

           && jourEntry.AccountingDate <= toDate

    {

        xlsWorkSheet.cells().item(row,1).value(jourEntry.AccountingDate);

        xlsWorkSheet.cells().item(row,2).value(jourEntry.SubledgerVoucher);

        xlsWorkSheet.cells().item(row,3).value(enum2str(jourAccEntry.PostingType));

        xlsWorkSheet.cells().item(row,4).value(jourAccEntry.LedgerAccount);


        row++;

    }

    info("Done");


    //Check whether the document already exists

    if(WinApi::fileExists(fileName))

        WinApi::deleteFile(fileName);

    //Save Excel document

    xlsWorkbook.saveAs(fileName);

    //Open Excel document

    xlsApplication.visible(true);

    //Close Excel

    //xlsApplication.quit();

    //xlsApplication.finalize();

}

0 comments:

A financial dimension value is based on the LAND-00013 record and has been used on a transaction. You cannot delete the LAND-00013 record AX 2012

 A financial dimension value is based on the LAND-00013 record and has been used on a  transaction. You cannot delete the LAND-00013 record ...