Come sappiamo, le classi STD per importare/esportare excel che AX mette a disposizione, (SysExcelApplication,SysExcelApplication_XP,SysExcelApplication_2007.. etc) non sono in grado di girare in batch perchè marcate come "client":
Per poter importare/esportare file in excel in batch occorre usare un componente esterno: ClosedXML:
https://www.nuget.org/packages/ClosedXML/
Una volta scaricata la DLL
https://drive.google.com/file/d/1AraBmgypormDRpLNfh_9WnDR6M77iJmz/view?usp=sharing
ed importata come reference in ax possiamo utilizzarla per esempio così:
ClosedXML.Excel.XLWorkbook workbook;
ClosedXML.Excel.IXLWorksheet worksheet;
ClosedXML.Excel.IXLCell cell;
CustTable custTable;
int row,
col;
try
{
workbook = new ClosedXML.Excel.XLWorkbook();
worksheet = workbook.AddWorksheet("Customers");
row = 1;
while select firstOnly10 CustTable
{
col = 1;
cell = worksheet.Cell(row,col);
cell.set_Value(CustTable.AccountNum);
col++;
cell = worksheet.Cell(row,col);
cell.set_Value(CustTable.name());
col++;
row++;
}
workbook.SaveAs(@'\\MyServer\Temp\lil01.xlsx');
}
catch(Exception::CLRError)
{
throw error (AifUtil::getClrErrorMessage());
}
info("Terminato!");