aidhound / hotxlfp

A Python Excel Formula Parser similar to the javascript handsontable formulaparser
MIT License
27 stars 12 forks source link

support for TEXT function #14

Closed Patroii closed 3 weeks ago

leonelcamara commented 3 months ago

This is pretty good, however the pandas dependency is unnecessary just to use pd.to_datetime, because you could just do this:

if isinstance(value, (datetime.datetime, datetime.date)):
    if isinstance(value, datetime.date):
        value = datetime.datetime(year=value.year, month=value.month, day=value.day)

To make sure you have a datetime and not a date.

There are some tests that don't seem right as well:

        ret = p.parse('TEXT(100,"$#,##0")')
        self.assertEqual(ret['result'], '$100')

The result should be '$100,000' not '$100'. Let me know if you plan on picking this up, otherwise I'll take it as it is and make the fixes. Thanks!

Patroii commented 3 months ago

Thanks for the feedback!

I've updated the code to avoid the unnecessary pandas dependency.

Regarding the TEXT function test, the correct result for =TEXT(100,"$#,##0") is $100, not $100,000. If the number were 100000, it would then format to $100,000 due to the comma separator in the format string.