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 :
Microsoft Dynamics AX (Archived)

Import Excel file through batch job in AX 2012 R3

(0) ShareShare
ReportReport
Posted on by 815

Hi,

Is there a way to import excel file in to AX using batch job.

Export to Excel using batch job works fine using below but is there a way to import excel data in Batch as well?

Microsoft.Dynamics.AX.Fim.Spreadsheets.Spreadsheet spreadsheet;

Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties cellProperties;

Microsoft.Dynamics.AX.Fim.Spreadsheets.ColumnProperties columnProperties;

Thanks,

Nadeem

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    hi Nadeem,

    There is no difference exicuting the code in the button or a JOB is same.

     you can use this code for your need

    void clicked()

    {

        SysExcelApplication application;

        SysExcelWorkbooks workbooks;

        SysExcelWorkbook workbook;

        SysExcelWorksheets worksheets;

        SysExcelWorksheet worksheet;

        SysExcelCells cells;

        COMVariantType type;

        Name name;

        FileName filename;

        LogisticsPostalAddress  postalAddress;

       DirPartyLocation partyLocation;

       int row =1;

        int i=0;

        MTCustAddress  custAddress;

        LogisticsPostalAddress LogisticsPostalAddress;

        InventTable        inventTableLoc;

        CustAccount        custAcc;

        LogisticsAddressing    address;

        LogisticsAddressCountyId   county;

        CustTable          custTable;

        ItemId                     itemid;

        str      ERPItemCode;

        Dialog dialog;

        DialogField dialogField;

        ;

        application = SysExcelApplication::construct();

        workbooks = application.workbooks();

        //specify the file path that you want to read

        //filename = “C:\\Users\\46509010\\Desktop\\book2.xlsx”;

        //filename = "C:\\Users\\Administrator\\Desktop\\LabelFields.xlsx";

       dialog = new Dialog("FileOpen");

       dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");

       dialog.run();

       if (dialog.run())

       {

           filename = (dialogfield.value());

       }

       //delete_from overtime

        //where overtime.MZK_MonthYear == MZK_MonthYear::APR2013

        //&& overtime.dataAreaId == “yme”;

       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

        {

            ttsBegin;

        row++;

        itemid = cells.item(row, 1).value().bStr();

        ERPItemCode = cells.item(row, 2).value().bStr();

           inventTableLoc = InventTable::find(itemid,true);

       inventTableLoc.ItemId = itemid;

       inventTableLoc.ERPItemCode = ERPItemCode;

        inventTableLoc.update();

            ttsCommit;

       i++;

        type = cells.item(row+1, 1).value().variantType();

       }

        while (type != COMVariantType::VT_EMPTY);

       application.quit();

        info("Done");

       info(strFmt("%1", i));

    }

    Thanks and Regards,

    Suresh

  • Nadeem Profile Picture
    815 on at

    Hi,

    SysExcelApplication  doesn't work in batch as I have tried this, that is why I used below for exporting to Excel but looking for reading from Excel.

    Microsoft.Dynamics.AX.Fim.Spreadsheets.Spreadsheet

  • Community Member Profile Picture
    on at

    Hi,

       May be your right Nadeem, Y your trying to do import from Batch, what is the Specific resone?

    Suresh

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    The tool that AX offers for this kind of scenario is Data Import Export Framework.

    It supports both Excel files and batch processing.

  • Verified answer
    Nadeem Profile Picture
    815 on at

    Hi,

    Biztalk will be used to convert the Excel file to CSV before moving it to the Import folder for AX to import as CSV file. DIXF is also an option but it adds extra design work so currently coverting excel file to CSV using Biztalk and then import CSV file in batch is the solution.

    Regards,

    Nadeem

  • Nadeem Profile Picture
    815 on at

    Also Question arises that DIXF is using AX batch job as well when importing data to staging so why can't AX read the excel through batch.

    Regards,

    Nadeem

  • Community Member Profile Picture
    on at

    Csv import is working in batch. You can use the TextIO class to do so. The only thing that doesn't work is .xls because you need to use the Excel classes which don't work in batch. If you convert it to .csv beforehand anyway, you can create a simple .csv batch import.

  • Community Member Profile Picture
    on at

    Hi Nadeem,

    I have used Speadsheet for export excel thru batchjob success, but I can't import excel with spreadsheet.

    Can you show your code for import ?

    Thank and regard,

    Thuyen Dang

  • Nadeem Profile Picture
    815 on at

    Try below link.

    axpedia.blogspot.co.uk/.../import-from-excel-file-using-x-in-ax.html

  • Community Member Profile Picture
    on at

    Hi Nadeem,

    SysExcelApplication  cannot work with batch job !

    Thanks,

    Thuyen Dang

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans