Friday 14 October 2016

Export Obsolete Material from AX to Excel

static void ExportObsoluteItemIntoExcel(Args _args)
{

EcoResProduct ecoResProduct;
 
//EcoResProductMaster ecoResProductMaster;


InventTable inventTable;

SysExcelApplication application;

SysExcelWorkbooks workbooks;

SysExcelWorkbook workbook;

SysExcelWorksheets worksheets;

SysExcelWorksheet worksheet;

SysExcelCells cells;

SysExcelCell cell;

SysExcelFont font;

int row = 1;


application = SysExcelApplication::construct();

workbooks = application.workbooks();

workbook = workbooks.add();

worksheets = workbook.worksheets();

worksheet = worksheets.itemFromNum(1);

cells = worksheet.cells(); 
cells.range('A:A').numberFormat('@');

// Setting Header values

/*cell = cells.item(1, 1);

cell.value("Item number");

font = cell.font();

font.bold(true);*/

cells.item(1, 1).value("Item number");

cells.item(1, 1).font().bold(true);

cells.item(1, 2).value("Search name");

cells.item(1, 2).font().bold(true);

cells.item(1, 3).value("Item name");

cells.item(1, 3).font().bold(true);

while select ecoResProduct

where ecoResProduct.SearchName == "Obsolete"

|| ecoResProduct.SearchName == "Use to Depletion"
{
row++;
/*cell = cells.item(row, 1);
cell.value(ecoResProduct.DisplayProductNumber);*/ cells.item(row, 1).value(ecoResProduct.DisplayProductNumber);

cells.item(row, 2).value(ecoResProduct.SearchName);

cells.item(row, 3).value(ecoResProduct.productName());
}application.visible(true);
}

No comments:

Post a Comment