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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Importing real values from Excel

(0) ShareShare
ReportReport
Posted on by 575

In inventtableinventsetup i have to read two fields Lowest qty and maximum qty which is of REAL type.I dono how to use Realtype in my code.Can You please help me on that

   static void ReadExcelfile(Args _args)
{

    SysExcelApplication         application;
    SysExcelWorkbooks           workbooks;
    SysExcelWorkbook            workbook;
    SysExcelWorksheets          worksheets;
    SysExcelWorksheet           worksheet;
    SysExcelCells               cells;
    Filename                    filename;
    COMVariantType              type;
    int                         rowNo;
    InventTable       HarmonizedMainAccount;
    InventItemInventSetup   inventsetup;
    EcoResDistinctProduct  DISTINCTPRODUCTS;
    InventDim              inventdim;
    real                   comvariant2real;
    str COMVariant2Str(COMVariant _cv, int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
    {
        switch (_cv.variantType())
        {
            case (COMVariantType::VT_BSTR):
            return _cv.bStr();
            case (COMVariantType::VT_R4):
            return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);
            case (COMVariantType::VT_R8):
            return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
            case (COMVariantType::VT_DECIMAL):
            return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);
            case (COMVariantType::VT_DATE):
            return date2str(_cv.date(),123,2,1,2,1,4);
            case (COMVariantType::VT_INT):
            return num2str( _cv.int(),_characters,_decimals,_separator1,_separator2);
            case (COMVariantType::VT_EMPTY):
            return "";
            default: throw error(strfmt("@SYS26908", _cv.variantType())); } return "";
    }

    rowNo   = 2;//If the excel file having header.

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    filename = @"C:\STEVENEXCEL";//Excel 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);//which shows excel sheet number.
    cells = worksheet.cells();

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

    while (type != COMVariantType::VT_EMPTY)//loop through given excel column.
    {
        type = cells.item(rowNo+1, 1).value().variantType();//It will find variant type of column from given Excel sheet(ReadIntegerFile.xlsx) tiil it get empty.

        HarmonizedMainAccount.clear();

       HarmonizedMainAccount.ItemId = COMVariant2Str(cells.item(rowNo, 1).value());
       // HarmonizedMainAccount.NameAlias = COMVariant2Str(cells.item(rowNo, 2).value());//nome conta plano atual
        inventdim.InventSiteId = COMVariant2Str(cells.item(rowNo, 2).value());
        inventsetup.LowestQty =
        inventsetup.HighestQty =

       info(strFmt("ItemID %1", HarmonizedMainAccount.ItemId));
       info(strFmt("Inventsiteid %1",inventdim.InventSiteId));

       // DISTINCTPRODUCTS.ProductType = EcoResProductType::Item;
       // HarmonizedMainAccount.initFromEcoResProduct(DISTINCTPRODUCTS);

        //Conta plano harmonizado
       // HarmonizedMainAccount.HarmonizedName = COMVariant2Str(cells.item(rowNo, 4).value());//nome conta valor harmonizado

        //HarmonizedMainAccount.insert();

        rowNo++;//To get next column number in the loop.
    }

   // info('fim');

    application.quit();
}

*This post is locked for comments

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

    Try this:

    inventDim.InventSiteId = cells.item(rowNo, 2).value().bStr();
    inventSetup.LowestQty  = cells.item(rowNo, 3).value().double();
  • Suggested answer
    Rudi Hansen Profile Picture
    4,079 on at

    Perhaps you should use a method to receive the values from fields in the Excel sheet, i did that to try to handle all conversion tasks in one place.

    anytype getExcelCellValue(int _row,
                              int _col)
    {
        anyType retVal;
        ;
        comVariantType    = sysExcelCells.item(_row, _col).value().variantType();
        switch (comVariantType)
        {
            case COMVariantType::VT_BSTR  :
                retVal = sysExcelCells.item(_row, _col).value().bStr();
                break;
            case COMVariantType::VT_R8    :
                retVal = sysExcelCells.item(_row, _col).value().double();
                break;
            case COMVariantType::VT_DATE  :
                retVal = sysExcelCells.item(_row, _col).value().date();
                break;
            case COMVariantType::VT_EMPTY :
                retVal = sysExcelCells.item(_row, _col).value().bStr();
                break;
            default :
                retVal = "";
                break;
        }
        return retVal;
    }


  • Ann2015 Profile Picture
    1,128 on at

    I am doing this in the excl upload.  Id which is Integer and TiemOff is real number. I am getting error

    'Argument TimeOff" is incompatible with the required type.  Can you please help?

    t this.updateHcmWorker(this.COMVariant2Str(cells.item(row,any2int(map.lookup("ID"))).value()),this.COMVariant2Str(cells.item(row,any2int(map.lookup("TimeOff"))).value()));

    Thank you

  • Martin Dráb Profile Picture
    239,647 Most Valuable Professional on at

    I think your main problem is that you didn't bother to identify which one of those 11 methods failed. Please do it and the it will all become much clearer.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Michael Adam ,

    As Martin said exact answer.

    If you have still doubt on your requirement, please look into my blog.

    http://axsuresh.blogspot.in/2016_03_01_archive.html (Import Excel)

    it may useful for you.

    Thanks,

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 34

#2
Michel ROY Profile Picture

Michel ROY 14

#3
Jagadabi Profile Picture

Jagadabi 6

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans