Print To Excel

Return To AX Content

//Printing to an excel file
{
sysExcelApplication excel = sysExcelApplication::construct();
sysExcelWorkSheet worksheet;
container worksheetRow;
common currentRecord;
int columns, rows;
;
excel.workbooks().add();

worksheet = excel.workbooks().item(1).worksheets().itemFromNum(1);

// Getting the data using a query. currentRecord gets the data.
// Filling the worksheetRow using another method, depending on fieldtype, etc.
for (columns = 1 ; columns <= conlen(worksheetRow);columns++)
{

worksheet.cells().item(rows,columns).value(conpeek(worksheetRow,columns));
}
worksheetRow = connull();

excel.save();
excel.visible(true);
}

SysExcelApplication::construct() contains this piece of code:

excel = COM::getObject(#EXCEL);
if (! excel)
excel = new COM(#EXCEL);

Return To AX Content