Example export data to excel in AX 2012
void exportToExcel()
{
SysExcelApplication application;
SysExcelWorkBooks workbooks;
SysExcelWorkBook workbook;
SysExcelWorksheets worksheets;
sysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//gets the workbook object
workbook = workbooks.add();
// creates a new workbook
worksheets = workbook.worksheets();
//gets the worksheets object
worksheet = worksheets.itemFromNum(1);
//Selects the first worksheet in the workbook to insert data
cells = worksheet.cells();
cells.range('A:A').numberFormat('@'); // numberFormat ‘@’ is to insert data as Text
row = 1;
cell = cells.item(row,1);
cell.value("TransactionType");
cell = cells.item(row,2);
cell.value("StoreNumber");
cell = cells.item(row,3);
cell.value("Date");
while select _CPRetailTransReport order by _CPRetailTransReport.StoreNumber, _CPRetailTransReport.Date, _CPRetailTransReport.TransactionType
//The following loop will provide the data to be populated in each column
{
row++;
cell = cells.item(row,1);
cell.value(_CPRetailTransReport.TransactionType);
cell = cells.item(row,2);
cell.value(_CPRetailTransReport.StoreNumber);
cell = cells.item(row,3);
cell.value(subStr(strFmt("%1",_CPRetailTransReport.Date),1,10));
}
application.visible(true); // opens the excel worksheet }
}
void exportToExcel()
{
SysExcelApplication application;
SysExcelWorkBooks workbooks;
SysExcelWorkBook workbook;
SysExcelWorksheets worksheets;
sysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//gets the workbook object
workbook = workbooks.add();
// creates a new workbook
worksheets = workbook.worksheets();
//gets the worksheets object
worksheet = worksheets.itemFromNum(1);
//Selects the first worksheet in the workbook to insert data
cells = worksheet.cells();
cells.range('A:A').numberFormat('@'); // numberFormat ‘@’ is to insert data as Text
row = 1;
cell = cells.item(row,1);
cell.value("TransactionType");
cell = cells.item(row,2);
cell.value("StoreNumber");
cell = cells.item(row,3);
cell.value("Date");
while select _CPRetailTransReport order by _CPRetailTransReport.StoreNumber, _CPRetailTransReport.Date, _CPRetailTransReport.TransactionType
//The following loop will provide the data to be populated in each column
{
row++;
cell = cells.item(row,1);
cell.value(_CPRetailTransReport.TransactionType);
cell = cells.item(row,2);
cell.value(_CPRetailTransReport.StoreNumber);
cell = cells.item(row,3);
cell.value(subStr(strFmt("%1",_CPRetailTransReport.Date),1,10));
}
application.visible(true); // opens the excel worksheet }
}
Komentar
Posting Komentar