Exporting data from AX to Excel
static void DemoExporttoExcel(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
InventDimCombination inventDimCombination;
InventDim inventDim;
int row = 1;
str fileName;
;
//Filename
fileName = "C:\\demo";
//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("Item id");
xlsWorkSheet.cells().item(row,2).value("Size");
xlsWorkSheet.cells().item(row,3).value("Colour");
xlsWorkSheet.cells().item(row,4).value("Style");
xlsWorkSheet.cells().item(row,5).value("Configuration");
row++;
//Fill Excel with CustTable AccountNum and Name fields (only 10 records)
while select inventDimCombination
join inventDim where
inventDim.inventDimId == inventDimCombination.InventDimId
{
xlsWorkSheet.cells().item(row,1).value(inventDimCombination.ItemId);
xlsWorkSheet.cells().item(row,2).value(inventDim.InventSizeId);
xlsWorkSheet.cells().item(row,3).value(inventDim.InventColorId);
xlsWorkSheet.cells().item(row,4).value(inventDim.InventStyleId);
xlsWorkSheet.cells().item(row,5).value(inventDim.configId);
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();
}
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
InventDimCombination inventDimCombination;
InventDim inventDim;
int row = 1;
str fileName;
;
//Filename
fileName = "C:\\demo";
//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("Item id");
xlsWorkSheet.cells().item(row,2).value("Size");
xlsWorkSheet.cells().item(row,3).value("Colour");
xlsWorkSheet.cells().item(row,4).value("Style");
xlsWorkSheet.cells().item(row,5).value("Configuration");
row++;
//Fill Excel with CustTable AccountNum and Name fields (only 10 records)
while select inventDimCombination
join inventDim where
inventDim.inventDimId == inventDimCombination.InventDimId
{
xlsWorkSheet.cells().item(row,1).value(inventDimCombination.ItemId);
xlsWorkSheet.cells().item(row,2).value(inventDim.InventSizeId);
xlsWorkSheet.cells().item(row,3).value(inventDim.InventColorId);
xlsWorkSheet.cells().item(row,4).value(inventDim.InventStyleId);
xlsWorkSheet.cells().item(row,5).value(inventDim.configId);
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();
}
Comments
Post a Comment