none
Excel Add-Ins: Which is the safest way to extract values from cells? RRS feed

  • Question

  • I am familiar with other Excel development environment. I always extract the cell value as text and after that, I convert it to double or whatever.

    My current target workbook may have some inconsistencies, such as "Number of Items" which is logically an int, is stored in Excel as floating point. My code relies on that cell's contents being stored as a real number.

    Should I check the cell format first, and depending on it, implement a retrieval strategy?

    TIA

    Tuesday, June 5, 2018 8:39 PM

Answers

  • Hello Travis Banger,

    There is no safest but safer way to extract value from cells based on your requirement.

    Get cell value as Text? I would suggest you get the Cell.Value instead of Cell.Text. The result should be a dymanic type. We could use Information.TypeName Method to get the type name of the value, a string or double or date. etc.

    What you said an int value is stored as floating point is right. All the Number is stored as double number and this is by design,so we could not change it. Once you get a double number, you could continue to confirm if it is a integer.

    See the thread for more help:How to determine if a decimal/double is an integer?

    I do not think check cell format is helpful to check the value type. Even I format a cell as number format, I could still enter string value in it.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Wednesday, June 6, 2018 5:55 AM