import excel file to insert in table

Hi guys,

I want to import the Excel File in Ax2012 the values in Excel file should be inserted in the AOT Tabled

Refer below code.

void clicked()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
FileName filename;
;

application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = “D:\econnector\output\FordSalesLine.xls”; // Excel file path.
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(“File cannot be opened.”);
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
datasourceTable.filed1 = cells.item(row, 1).value().bStr();
datasourceTable.filed2 = cells.item(row, 2).value().bStr();
datasourceTable.filed3 = cells.item(row, 3).value().date(); // if filed datatype is date
datasourceTable.filed4 = cells.item(row, 4).value().double(); //if filed datatype is real
type = cells.item(row+1, 1).value().variantType();
datasourceTable.insert();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();

info(“File Uploaded Successfully…”);

datasourceTable_ds.refresh();
datasourceTable_ds.research();
datasourceTablee_ds.reread();
super();
}

Post is from AX 2009.

hi,
I want to do it in JOb dude. Can u Send me the code using the Job file??

Just copy paste above code (Modify code as per your requirement) in your job and run …that’s it.

Here is another way to do this in AX 2012 via the Excel Add-in

Importing a Budget via the Excel Add-in

Hi,

Can you try Excel addins feature.

sample functionality is given below

anithasantosh.wordpress.com/…/