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)

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

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

  • veera seenivasan Profile Picture
    575 on at

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

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    open() method definitely accepts a string.

    Please show us your new code.

  • veera seenivasan Profile Picture
    575 on at

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

    }

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    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
    575 on at

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

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    "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
    575 on at

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

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    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.

  • Crisdu Profile Picture
    20 on at

    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"

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans