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)

how to convert excel number value to string in axapta

(0) ShareShare
ReportReport
Posted on by

i have created an upload facility in axapta 3.0 where user can upload there transaction from excel to axapta. the problem arises when some column contains number value and my field in axapta is string so that i used the below code:

 

 RCell = Cells.Item(ExcelRowNo, 11);
        accNo  = RCell.value().bStr();

but not getting the value if number but it returns the value text or i change the excel column format to text

 

Help

*This post is locked for comments

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

    You could try using any2str(the_cell_value_unassigned_to_Axapta_type)

  • Community Member Profile Picture
    on at

    i tried using strfmt and aslo any2str but the value iam getting is "100023.0000 VT_BSTR" were in my excel cell value is 100023 and i want only this value i dont know why is it formatting in VT_BSTR

  • Verified answer
    Community Member Profile Picture
    on at

    When you’re importing data from Excel, you need to check what the variant type for Excel cell is, and do the appropriate conversion. This way you can avoid problems with different cell formatting, e.g. if some cells are strings (BSTR), while other were formatted as some of the number types. You can use the code below, it checks the variant type (using the variantType() method for a given cell), and then depending on variant type do the appropriate conversion to get the account number as string value:

    switch(RCell.value().variantType())
    {
        case COMVariantType::VT_BSTR:
            accNo = strFmt("%1", RCell.value().bStr());
            break;
        case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
            accNo = strFmt("%1", any2int(RCell.value().double()));
            break;
        case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
            accNo = strFmt("%1", RCell.value().int());
            break;
        case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
            accNo = strFmt("%1", RCell.value().uLong());
            break;
         case COMVariantType::VT_EMPTY:
            accNo = '';
            break;
        default:
            throw error(strfmt('Unhandled variant type (%1).', RCell.value().variantType()));
    }

  • Mel Cabillada III Profile Picture
    425 on at

    Yes the solution posted by jovan worked for me.  Thanks.

  • Barney LEE Profile Picture
    60 on at

    Yes, these codes also works for my application. Exporting and converting excel number value to string in axapta is a little difficult for me who is a newbie for document programming. 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

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