Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

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

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();


}

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: getting data from excel file ax 2012 then manipulate it using SQL and x++

    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.

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: getting data from excel file ax 2012 then manipulate it using SQL and x++

    Hi Kareem,

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

    Best regards,

    Ludwig

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans