Create simple excel File Ax-2012
static void SomesCreateExl(Args _args)
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
CustTable custTable;
int row = 1;
str fileName;
;
//Filename
fileName = "E:\\Test.xlsx";
//Initialize Excel instance
xlsApplication = SysExcelApplication::construct();
//Open Excel document
//xlsApplication.visible(true);
//Create Excel WorkBook and WorkSheet
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
//Excel columns captions
xlsWorkSheet.cells().item(row,1).value("Account Num");
xlsWorkSheet.cells().item(row,2).value("InvoiceAddress");
xlsWorkSheet.cells().item(row,3).value("BankAccount");
xlsWorkSheet.cells().item(row,4).value("CreditMax");
xlsWorkSheet.cells().item(row,5).value("Currency");
row++;
//Fill Excel with CustTable AccountNum and Name fields (only 20 records)
while select custTable
{
if(row == 71)
break;
xlsWorkSheet.cells().item(row,1).value(custTable.AccountNum);
xlsWorkSheet.cells().item(row,2).value(custTable.InvoiceAddress);
xlsWorkSheet.cells().item(row,3).value(custTable.BankAccount);
xlsWorkSheet.cells().item(row,4).value(custTable.CreditMax);
xlsWorkSheet.cells().item(row,5).value(custTable.Currency);
row++;
}
//Check whether the document already exists
if(WinApi::fileExists(fileName))
WinApi::deleteFile(fileName);
//Save Excel document
xlsWorkbook.saveAs(fileName);
//Open Excel document
xlsApplication.visible(true);
//Close Excel
//xlsApplication.quit();
//xlsApplication.finalize();
}
{
SysExcelApplication xlsApplication;
SysExcelWorkBooks xlsWorkBookCollection;
SysExcelWorkBook xlsWorkBook;
SysExcelWorkSheets xlsWorkSheetCollection;
SysExcelWorkSheet xlsWorkSheet;
SysExcelRange xlsRange;
CustTable custTable;
int row = 1;
str fileName;
;
//Filename
fileName = "E:\\Test.xlsx";
//Initialize Excel instance
xlsApplication = SysExcelApplication::construct();
//Open Excel document
//xlsApplication.visible(true);
//Create Excel WorkBook and WorkSheet
xlsWorkBookCollection = xlsApplication.workbooks();
xlsWorkBook = xlsWorkBookCollection.add();
xlsWorkSheetCollection = xlsWorkBook.worksheets();
xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);
//Excel columns captions
xlsWorkSheet.cells().item(row,1).value("Account Num");
xlsWorkSheet.cells().item(row,2).value("InvoiceAddress");
xlsWorkSheet.cells().item(row,3).value("BankAccount");
xlsWorkSheet.cells().item(row,4).value("CreditMax");
xlsWorkSheet.cells().item(row,5).value("Currency");
row++;
//Fill Excel with CustTable AccountNum and Name fields (only 20 records)
while select custTable
{
if(row == 71)
break;
xlsWorkSheet.cells().item(row,1).value(custTable.AccountNum);
xlsWorkSheet.cells().item(row,2).value(custTable.InvoiceAddress);
xlsWorkSheet.cells().item(row,3).value(custTable.BankAccount);
xlsWorkSheet.cells().item(row,4).value(custTable.CreditMax);
xlsWorkSheet.cells().item(row,5).value(custTable.Currency);
row++;
}
//Check whether the document already exists
if(WinApi::fileExists(fileName))
WinApi::deleteFile(fileName);
//Save Excel document
xlsWorkbook.saveAs(fileName);
//Open Excel document
xlsApplication.visible(true);
//Close Excel
//xlsApplication.quit();
//xlsApplication.finalize();
}
No comments:
Post a Comment