Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Can't open Excel file for import

(0) ShareShare
ReportReport
Posted on by 575

Hi All,

          My Requirement is to Read to a Excel file Through Job .I am Facing this issue while running.I need to Read the excel file and display in info.I have written my code for your reference.Please Help Me to fix this.Thanks in Advance.Experts send some Tested code.

issue:  Method 'item' in COM object of class 'Workbooks' returned error code 0x8002000B (<unknown>) which means: <unknown>.


x++ code:

  static void veeraExcel(Args _args)
{

 SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
InventDim inventdim;
InventSiteId inventsiteid;
InventItemInventSetup  inventsetup;

Name name;
FileName filename;

;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename ="C:\\item.xls";
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
inventsiteid = cells.item(row, 2).value().bStr();
inventsetup.LowestQty= cells.item(row, 3).value().int();
inventsetup.HighestQty=cells.item(row, 4).value().int();
//editHighestQty= cells.item(row, 3).value().bStr();

info(strfmt('%1 - %2- %3- %4', itemId, inventsiteid,inventsetup.LowestQty,inventsetup.HighestQty));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();

}


*This post is locked for comments

  • Crisdu Profile Picture
    Crisdu 20 on at
    RE: Can't open Excel file for import

    Hello together,

    i have found the Problem why it did not work any more.

    The Problem results form the FoxitReader.

    Wy, i can not tell you. But after deinstalling this Software, Excel works as known.

    Dynamics AX 4.0 works with Office 2016

    "Mikra  responded on 2 Aug 2017 7:49 AM"

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    RE: Importing Excel file

    Then it means (most likely) either that the file doesn't exist (you misspelled the name, you're trying to access a file from server that actually exists only on client's machine or so) or that the process running the code doesn't have permissions to read the code.

    The most common reason is that developers don't pay attention to whether their code is running on server or client. I suggest you verify this as the very first step.

  • veera seenivasan Profile Picture
    veera seenivasan 575 on at
    RE: Importing Excel file

    Sorry Martin "C:\\item.xls"  I changed now. Still Facing the Same issue

  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    RE: Importing Excel file

    "C:\item.xls" is wrong again. Please use one of those two correct options I gave you in my previous reply.

  • veera seenivasan Profile Picture
    veera seenivasan 575 on at
    RE: Importing Excel file

    filename = "C:\item.xls" Still it showing the Same error.OR ExcelADDIN Should be Installed??

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    RE: Importing Excel file

    I'm not surprised that no such file exists, because @ C:\\item.xls isn't a valid path at all. You clearly intended to refer to C:\item.xls, which can be written down in X++ either as "C:\\item.xls" or @"C:\item.xls". The difference between these two is that the first one allows escape sequences such as \n, and therefore your need to escape the special character, backslash, with another backslash, while the second one don't allow escape sequences and backslash works as a normal character there, so there is no need to escape it.

  • veera seenivasan Profile Picture
    veera seenivasan 575 on at
    RE: Importing Excel file

    Hi Martin I Have  Added my new code But now i am getting different issue Just a beginner in Ax.  But I Have given the correct location for the file.Dono why its showing this error.

    1.Method 'open' in COM object of class 'Workbooks' returned error code 0x800A03EC (<unknown>) which means: '@ C:\item.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.

    2.File cannot be opened.

    static void Excel(Args _args)

    {

    SysExcelApplication application;

    SysExcelWorkbooks workbooks;

    SysExcelWorkbook workbook;

    SysExcelWorksheets worksheets;

    SysExcelWorksheet worksheet;

    SysExcelCells cells;

    SysExcelCell  cell;

    COMVariantType type;

    int row;

    ItemId itemid;

    InventDim inventdim;

    InventSiteId inventsiteid;

    InventItemInventSetup  inventsetup;

    Name name;

    FileName filename;

    ;

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    //specify the file path that you want to read

    filename ="@ C:\\item.xls";

      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++;

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

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

    inventsetup.LowestQty= cells.item(row, 3).value().int();

    inventsetup.HighestQty=cells.item(row, 4).value().int();

    //editHighestQty= cells.item(row, 3).value().bStr();

    info(strfmt('%1 - %2- %3- %4', itemId, inventsiteid,inventsetup.LowestQty,inventsetup.HighestQty));

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

    }

    while (type != COMVariantType::VT_EMPTY);

    application.quit();

    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    RE: Importing Excel file

    open() method definitely accepts a string.

    Please show us your new code.

  • veera seenivasan Profile Picture
    veera seenivasan 575 on at
    RE: Importing Excel file

    I added again i am getting an error that Operand types are not compatible with the operator

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    RE: Importing Excel file

    You forgot to open the file. Call workbooks.open(filename) before trying to access the content.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans