How to export table data in excel file in AX 2012

Hi Experts,

We have inbuilt classes to import/export data into excel file. We have robust features available where we can design worksheet, format text  & secure document beside just importing/exporting.

Lets start with today’s stuff on exporting data outside of AX into excel file. The following code writes table data into xls file.

SysExcelApplication     application;
SysExcelWorkbooks       workbooks;
SysExcelWorkbook        workbook;
SysExcelWorksheets      worksheets;
SysExcelWorksheet       worksheet;
SysExcelCells           cells;
SysExcelCell            cell;
SysExcelFont            font;
int                     row;
YourTable yourTable;

// intializing classes to export excel
application = SysExcelApplication::construct();
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(“HeaderValue1”);
font = cell.font();
font.bold(true);

cell = cells.item(1, 2);
cell.value(“HeaderValue2”);
font = cell.font();
font.bold(true);
row = 1;

// inserting data row wise
while select yourTable
{
row++;
cell = cells.item(row, 1);
cell.value(yourTable.field1);
cell = cells.item(row, 2);
cell.value(yourTable.field2);
}

application.visible(true);

There are lot of things to discuss on exporting excel. I will share some link so that you can through these fruitful links.

The following link will help if you get error as “The number of arguments provided is different from the number of arguments accepted by the method.”

Coding Champ (Mohammed Zahid)

The following link will help if you get error as “the method has been called with an invalid number of parameters.”

Mohammed Afsar khan

Thanks & Happy Daxing……..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: