In the business process, its a very regular activity that imports data from an excel file to AX. for that business needs to maintain a proper and fixed template, in this scenario we have created one class to generate the excel file with required field. So user can easily generate the sample file every time if he required.
Here is the code
static void fileSampleGeneration()
{
SysExcelWorksheetHelper worksheetHelper;
SysExcelHelper sysExcelHelper;
SysExcelWorksheet worksheet;
#File
str worksheetName;
int i = 1;
;
worksheetName = "@PRU11";
sysExcelHelper = SysExcelHelper::construct();
sysExcelHelper.initialize();
worksheet = sysExcelHelper.addWorksheet(worksheetName);
worksheetHelper = SysExcelWorksheetHelper::construct(worksheet);
try
{
worksheetHelper.addColumn(i, "@SYS27207", Types::Real);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@WAX1240", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS11990", Types::Real);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS14614", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS14719", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS14462", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@WAX1614", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS78255", Types::Date);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@GLS112581", Types::Date);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS5755", Types::Real);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS83318", Types::Real);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SYS9913", Types::Real);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@SBC1788", Types::String);
worksheetHelper.autoFitColumns();
i ++;
worksheetHelper.addColumn(i, "@PRU311", Types::String);
worksheetHelper.autoFitColumns();
}
sysExcelHelper.launchExcel();
sysExcelHelper.save("@PRU11");
}
catch (Exception::Error)
{
exceptionTextFallThrough();
}
}
Thank you!!