Export to Excel/Word - COM-Interface
Axapta has subset of classes which can be used for exporting data into Excel via COM in your own way. You can find them in the AOT ( Application Object Tree ), they have 'SysExcel' prefix.
These classes are simply wrappers around COM class.
The following simple example shows how output data about employees into already prepared Excel template.
static void ExcelAPITestJob(Args _args) { SysExcelApplication excelApp = SysExcelApplication::construct(); SysExcelWorkSheet excelWorksheet; SysExcelRange excelRange; SysExcelCells excelCells; SysExcelCell excelCell; ComVariant cellValue = new ComVariant() ; EmplTable empTable; int i; // Open our template file excelApp.workbooks().open( 'c:\\tmp\\empl_rep.xlt' ); // Obtain first worksheet excelWorksheet = excelApp.worksheets().itemFromNum( 1 ); // Obtain cells on that worksheet excelCells = excelWorksheet.cells(); // select data from employee's table and output EmplId and Name into our template while select empTable { excelCells.item( 5 + i, 2 ).value( cellValue.bStr( empTable.EmplId ) ); excelCells.item( 5 + i, 3 ).value( cellValue.bStr( empTable.Name ) ); i++; } excelApp.visible( true ); }
The example above uses Excel template, you should download it before running that code. To download template file click here (WARNING!!!. You have to replace 'xpo' extension with 'xlt' after downloading it.)
See also SysExcelTemplateWizard