static void DASCreateExcelDocument(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
CustTable custTable;
int row = 1;
str fileName;
;
//Filename
fileName = "C:\\Test.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("Account Num");
xlsWorkSheet.cells().item(row,2).value("Name");
row++;
//Fill Excel with CustTable AccountNum and Name fields (only 10 records)
while select custTable
{
if(row == 10)
break;
xlsWorkSheet.cells().item(row,1).value(custTable.AccountNum);
xlsWorkSheet.cells().item(row,2).value(custTable.Name);
row++;
}
//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();
}
Welcome to Axapta forum for learning, sharing and transferring dynamics AX knowledge and all related topics to Dynamics AX for example Business Intelligence (SSRS & SSAS), SQL, Workflow, SharePoint, ALL Dynamics AX Reporting tools, AX Integration ( AIF, Web Service, ...)
LeaderBoard
Exporting data to Excel by Code x++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment