Export to excel in ax 2012 x++
void clicked()
{
/* #AviFiles
DimensionAttributeValueSetStorage dimStorage;
Counter i;
DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
DimensionAttribute dimAttr;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
SysExcelFont font;
int row,sleepCount = 1000;
DimensionValue bl,dept,project,worker,vehicle;
GeneralJournalEntry generalJournalEntryExcel;
GeneralJournalAccountEntry generalJournalAccountEntryExcel;
GeneralJournalAccountEntry generalJournalAccountEntryLoc;
SysOperationProgress progressBar = new SysOperationProgress();
// intializing classes to export excel
application = SysExcelApplication::construct();
application.displayAlerts(false);
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("Journal Number");
font = cell.font();
font.bold(true);
cell = cells.item(1, 2);
cell.value("Date");
font = cell.font();
font.bold(true);
cell = cells.item(1, 3);
cell.value("Voucher");
font = cell.font();
font.bold(true);
cell = cells.item(1, 4);
cell.value("Ledger account");
font = cell.font();
font.bold(true);
cell = cells.item(1, 5);
cell.value("Year Closed");
font = cell.font();
font.bold(true);
cell = cells.item(1, 6);
cell.value("Currency code");
font = cell.font();
font.bold(true);
cell = cells.item(1, 7);
cell.value("Transaction currency amount");
font = cell.font();
font.bold(true);
cell = cells.item(1, 8);
cell.value("Reporting Currency amount");
font = cell.font();
font.bold(true);
cell = cells.item(1,9);
cell.value("Amount");
font = cell.font();
font.bold(true);
cell = cells.item(1,10);
cell.value("Posting layer");
font = cell.font();
font.bold(true);
cell = cells.item(1,11);
cell.value("Acknowledge");
font = cell.font();
font.bold(true);
cell = cells.item(1,12);
cell.value("Project");
font = cell.font();
font.bold(true);
cell = cells.item(1,13);
cell.value("worker");
font = cell.font();
font.bold(true);
cell = cells.item(1,14);
cell.value("vehicle");
font = cell.font();
font.bold(true);
cell = cells.item(1,15);
cell.value("Department");
font = cell.font();
font.bold(true);
cell = cells.item(1,16);
cell.value("Business Line");
font = cell.font();
font.bold(true);
try
{
row = 1;
startLengthyOperation();
while(queryRun.next())
{
generalJournalAccountEntryLoc = queryRun.get(tablenum(GeneralJournalAccountEntry));
select generalJournalAccountEntryExcel
join generalJournalEntryExcel where generalJournalAccountEntryExcel.GeneralJournalEntry == generalJournalEntryExcel.RecId
&& generalJournalAccountEntryExcel.RecId == generalJournalAccountEntryLoc.RecId;
bl = '';
dept = '';
project = '';
vehicle ='';
worker = '';
while select DisplayValue from dimAttrView
where dimAttrView.ValueCombinationRecId == generalJournalAccountEntryExcel.LedgerDimension
join BackingEntityType,Name from dimAttr
where dimAttr.RecId == dimAttrView.DimensionAttribute
{
switch (dimAttr.Name)
{
case 'BusinessLine':
bl = dimAttrView.DisplayValue;
break;
case 'Department':
dept = "'" + dimAttrView.DisplayValue;
break;
case 'Project':
project = "'" + dimAttrView.DisplayValue;
break;
case 'Vehicle':
vehicle = dimAttrView.DisplayValue;
break;
case 'Worker':
worker = "'" + dimAttrView.DisplayValue;
break;
}
}
row++;
cell = cells.item(row, 1);
cell.value(generalJournalEntryExcel.JournalNumber);
cell = cells.item(row, 2);
cell.value(generalJournalEntryExcel.AccountingDate);
cell = cells.item(row, 3);
cell.value(generalJournalEntryExcel.SubledgerVoucher);
cell = cells.item(row, 4);
cell.value(generalJournalAccountEntryExcel.LedgerAccount);
cell = cells.item(row, 5);
cell.value(generalJournalEntryExcel.displayIsFiscalYearClosed());
cell = cells.item(row, 6);
cell.value(generalJournalAccountEntryExcel.TransactionCurrencyCode);
cell = cells.item(row, 7);
cell.value(generalJournalAccountEntryExcel.TransactionCurrencyAmount);
cell = cells.item(row,8);
cell.value(generalJournalAccountEntryExcel.ReportingCurrencyAmount);
cell = cells.item(row, 9);
cell.value(generalJournalAccountEntryExcel.AccountingCurrencyAmount);
cell = cells.item(row, 10);
cell.value(generalJournalEntryExcel.PostingLayer);
cell = cells.item(row, 11);
cell.value(generalJournalEntryExcel.ALE_AcknowledgeNumber);
cell = cells.item(row, 12);
cell.value(project);
cell = cells.item(row, 13);
cell.value(worker);
cell = cells.item(row, 14);
cell.value(vehicle);
cell = cells.item(row, 15);
cell.value(dept);
cell = cells.item(row, 16);
cell.value(bl);
if(sleepCount == row)
{
sleepCount = sleepCount + 1000;
sleep(10000);
}
infolog.yield();
progressBar.setCaption(strfmt("Exporting the voucher transactions to excel",row));
progressBar.setAnimation(#AviUpdate);
progressBar.setText(strfmt("Processing %1 out of %2",row));
}
endLengthyOperation();
}
catch(Exception::Error)
{
throw(Exception::Error);
}
GeneralJournalAccountEntry_ds.reread();
GeneralJournalAccountEntry_ds.research();
application.visible(true);
application.finalize();
application = null;
*/
}
void clicked()
{
/* #AviFiles
DimensionAttributeValueSetStorage dimStorage;
Counter i;
DimensionAttributeLevelValueAllView dimAttrView; //View that will display all values for ledger dimensions
DimensionAttribute dimAttr;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
SysExcelFont font;
int row,sleepCount = 1000;
DimensionValue bl,dept,project,worker,vehicle;
GeneralJournalEntry generalJournalEntryExcel;
GeneralJournalAccountEntry generalJournalAccountEntryExcel;
GeneralJournalAccountEntry generalJournalAccountEntryLoc;
SysOperationProgress progressBar = new SysOperationProgress();
// intializing classes to export excel
application = SysExcelApplication::construct();
application.displayAlerts(false);
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("Journal Number");
font = cell.font();
font.bold(true);
cell = cells.item(1, 2);
cell.value("Date");
font = cell.font();
font.bold(true);
cell = cells.item(1, 3);
cell.value("Voucher");
font = cell.font();
font.bold(true);
cell = cells.item(1, 4);
cell.value("Ledger account");
font = cell.font();
font.bold(true);
cell = cells.item(1, 5);
cell.value("Year Closed");
font = cell.font();
font.bold(true);
cell = cells.item(1, 6);
cell.value("Currency code");
font = cell.font();
font.bold(true);
cell = cells.item(1, 7);
cell.value("Transaction currency amount");
font = cell.font();
font.bold(true);
cell = cells.item(1, 8);
cell.value("Reporting Currency amount");
font = cell.font();
font.bold(true);
cell = cells.item(1,9);
cell.value("Amount");
font = cell.font();
font.bold(true);
cell = cells.item(1,10);
cell.value("Posting layer");
font = cell.font();
font.bold(true);
cell = cells.item(1,11);
cell.value("Acknowledge");
font = cell.font();
font.bold(true);
cell = cells.item(1,12);
cell.value("Project");
font = cell.font();
font.bold(true);
cell = cells.item(1,13);
cell.value("worker");
font = cell.font();
font.bold(true);
cell = cells.item(1,14);
cell.value("vehicle");
font = cell.font();
font.bold(true);
cell = cells.item(1,15);
cell.value("Department");
font = cell.font();
font.bold(true);
cell = cells.item(1,16);
cell.value("Business Line");
font = cell.font();
font.bold(true);
try
{
row = 1;
startLengthyOperation();
while(queryRun.next())
{
generalJournalAccountEntryLoc = queryRun.get(tablenum(GeneralJournalAccountEntry));
select generalJournalAccountEntryExcel
join generalJournalEntryExcel where generalJournalAccountEntryExcel.GeneralJournalEntry == generalJournalEntryExcel.RecId
&& generalJournalAccountEntryExcel.RecId == generalJournalAccountEntryLoc.RecId;
bl = '';
dept = '';
project = '';
vehicle ='';
worker = '';
while select DisplayValue from dimAttrView
where dimAttrView.ValueCombinationRecId == generalJournalAccountEntryExcel.LedgerDimension
join BackingEntityType,Name from dimAttr
where dimAttr.RecId == dimAttrView.DimensionAttribute
{
switch (dimAttr.Name)
{
case 'BusinessLine':
bl = dimAttrView.DisplayValue;
break;
case 'Department':
dept = "'" + dimAttrView.DisplayValue;
break;
case 'Project':
project = "'" + dimAttrView.DisplayValue;
break;
case 'Vehicle':
vehicle = dimAttrView.DisplayValue;
break;
case 'Worker':
worker = "'" + dimAttrView.DisplayValue;
break;
}
}
row++;
cell = cells.item(row, 1);
cell.value(generalJournalEntryExcel.JournalNumber);
cell = cells.item(row, 2);
cell.value(generalJournalEntryExcel.AccountingDate);
cell = cells.item(row, 3);
cell.value(generalJournalEntryExcel.SubledgerVoucher);
cell = cells.item(row, 4);
cell.value(generalJournalAccountEntryExcel.LedgerAccount);
cell = cells.item(row, 5);
cell.value(generalJournalEntryExcel.displayIsFiscalYearClosed());
cell = cells.item(row, 6);
cell.value(generalJournalAccountEntryExcel.TransactionCurrencyCode);
cell = cells.item(row, 7);
cell.value(generalJournalAccountEntryExcel.TransactionCurrencyAmount);
cell = cells.item(row,8);
cell.value(generalJournalAccountEntryExcel.ReportingCurrencyAmount);
cell = cells.item(row, 9);
cell.value(generalJournalAccountEntryExcel.AccountingCurrencyAmount);
cell = cells.item(row, 10);
cell.value(generalJournalEntryExcel.PostingLayer);
cell = cells.item(row, 11);
cell.value(generalJournalEntryExcel.ALE_AcknowledgeNumber);
cell = cells.item(row, 12);
cell.value(project);
cell = cells.item(row, 13);
cell.value(worker);
cell = cells.item(row, 14);
cell.value(vehicle);
cell = cells.item(row, 15);
cell.value(dept);
cell = cells.item(row, 16);
cell.value(bl);
if(sleepCount == row)
{
sleepCount = sleepCount + 1000;
sleep(10000);
}
infolog.yield();
progressBar.setCaption(strfmt("Exporting the voucher transactions to excel",row));
progressBar.setAnimation(#AviUpdate);
progressBar.setText(strfmt("Processing %1 out of %2",row));
}
endLengthyOperation();
}
catch(Exception::Error)
{
throw(Exception::Error);
}
GeneralJournalAccountEntry_ds.reread();
GeneralJournalAccountEntry_ds.research();
application.visible(true);
application.finalize();
application = null;
*/
}
No comments:
Post a Comment