Wednesday, October 24, 2012

Print Main Menu

Question: How can i print all elements of a main menu.

Answer: Use the following job, 


static void menuPrint(Args _args)
{

    SysDictMenu menu;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelHelper sysExcelHelper;
    SysExcelWorksheet worksheet;
    str menuToPrint;
    str worksheetName;
    int currentRow = 1;
    str fileName;
    str path;

    void reportLevel(SysDictMenu _sysDictMenu)
    {

        SysMenuEnumerator enumerator;

        if(_sysDictMenu.isMenuReference() || _sysDictMenu.isMenu())
        {
            path += _sysDictMenu.label() + "//";
            enumerator = _sysDictMenu.getEnumerator();
            while (enumerator.moveNext())
            {
                reportLevel(enumerator.current());
            }
        }
        else
        {   currentRow ++;
            worksheetHelper.setCellValue(2, currentRow, _sysDictMenu.label());
            path = "";
        }
    }

    ;

    sysExcelHelper = SysExcelHelper::construct();
    sysExcelHelper.initialize();

    menuToPrint = 'Roster';
    worksheetName = menuToPrint;
    worksheet = sysExcelHelper.addWorksheet(worksheetName);
    worksheetHelper = SysExcelWorksheetHelper::construct(worksheet);
    // Populate the header row with the appropriate field labels and format the columns
    worksheetHelper.addColumn(1, "Path", Types::String);
    worksheetHelper.addColumn(2, "Item", Types::String);
    worksheetHelper.addColumn(3, "Status", Types::String);
    worksheetHelper.addColumn(4, "Assigned To", Types::String);
    worksheetHelper.addColumn(5, "Notes", Types::String);
    reportLevel(SysDictMenu::newMenuName(MenuStr(Roster)));
    worksheetHelper.autoFitColumns();
    worksheetHelper.formatWorksheetTableStyle(sysExcelHelper.getOfficeVersion());


    // Generate the file using the current UTC date time (without the ‘:’ character)
    // since it is not allowed for file names.
    fileName =  "C:\\Windows\\Temp\\ExportToExcel.xlsx";

    sysExcelHelper.save(filename);
    sysExcelHelper.launchExcel();
}