web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

getting data from excel file ax 2012 then manipulate it using SQL and x++

(0) ShareShare
ReportReport
Posted on by 45

static void UpdateSupplementaryQuantities(Args _args)
{

//initializing system excel objects to use

SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;

Filename filename;   //get the file name
COMVariantType type; //to check if it's the end
int rowNo; //getting the row number 

//here you get an object form your table 
YourTable _yourTable;

//initializing the requiered fields you want to handle, ehither you use there ExtendType or there actual data type

SomeExtendType     firstObject; 

str                             secondObject; 

//////
application = SysExcelApplication::construct();
workbooks = application.workbooks();


//specify the file path that you want to read
filename = @"your_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); //working with sheet one in the excel
cells = worksheet.cells(); // getting all the cells 
rowNo = 1;    //row number starts to count rows from 2 because usually the header is in the first row 
do
{
rowNo++;

//let's assume you have two columns 

firstObject  = cells.item(rowNo, 1).value().double();   

//you get the row number and then the column for the data you want and the value of it and it's double because it may have extend type but the original data type it's own data type and here it's real so we use double 

secondObject = cells.item(rowNo, 2).value().bStr();   // here we use bStr because our object's data type is string 


//now you have the data for the first record in the excel, you handle it using SQL and x++ 


ttsBegin;
 //your code goes here 

ttsCommit;


type = cells.item(rowNo+1, 1).value().variantType();  //here we check if the next row it's not empty 
}
while (type != COMVariantType::VT_EMPTY); // a loop to get the next rows
workbooks.close();


}

I have the same question (0)
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi Kareem,

    What do you try to achieve here actually and why you need excel based data from AX?

    Best regards,

    Ludwig

  • André Arnaud de Calavon Profile Picture
    301,146 Super User 2025 Season 2 on at

    Hi Kareem,

    It is not clear what data you want to insert in what table. However, you can use the data import export framework to import data from Excel files. That would probably prevent a customization.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans