Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Reading Excel files with different data types in same column

Posted on by 495

Hi 

I have to read excel file,

i can able to read string data with below code

conValue[recCount] += cells.item(row, fields[15]).value().bstr();

& i can able to read int data with below code 

conValue[recCount] += cells.item(row, fields[15]).value().double();

if i use

if(cells.item(row, fields[15]).value().double())
{
conValue[recCount] += cells.item(row, fields[15]).value().double();
}
else
{
conValue[recCount] += cells.item(row, fields[15]).value().bstr();
}

 

then few times sting values are are getting skipped while reading.

 

In my case i have both int & string values to be read.

please suggest how to read data of any type in excel.

 

*This post is locked for comments

  • Suggested answer
    RE: Reading Excel files with different data types in same column

    Hi Andre

    Thanks for the response , below solution worked for me

    if(cells.item(row, fields[15]).value().variantType() == COMVariantType::VT_BSTR)

                           {

                              conValue[recCount] += cells.item(row, fields[15]).value().bStr();

                           }

                           else

                           {

                               conValue[recCount] += cells.item(row, fields[15]).value().double();

                           }

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,269 Super User 2024 Season 2 on at
    RE: Reading Excel files with different data types in same column

    Hi Raghu,

    There are actually more cell types possible for Excel. You have to debug and see which types are used when the values are skipped. Then you know what is missing and you can extend the code for other Excel cell types.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans