Interview Questions

Tuesday, September 27, 2016

Writing Data to Excel file in AX

//X++ Code to write data from AX to Excel sheet

static void WriteAX2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
excel = SysExcelApplication::construct();
books = excel.workbooks();
book = books.add();
sheets = book.worksheets();
sheet = sheets.itemFromNum(1);
cells = sheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");

cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
excel.visible(true);
}

No comments:

Post a Comment