PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
303 stars 47 forks source link

.database.num2columnletters doesn't work properly with indexes above 727 (AAY) #19

Closed sehnryr closed 4 years ago

sehnryr commented 4 years ago

If the input was 728, we should espect "AAZ" but actually, the code returns "ABZ"

I could suggest to replace that function by :

def num2alpha(num: int) -> str:
    def pre_num2alpha(num) -> list:
        if num % 26 != 0:
            num = [num // 26, num % 26]
        else:
            num = [(num - 1) // 26, 26]

        if num[0] > 26:
            num = pre_num2alpha(num[0]) + [num[1]]
        else:
            num = list(filter(lambda x: False if x == 0 else True, num))

        return num

    return "".join(list(map(lambda x: chr(x + 64), pre_num2alpha(num))))

That should resolve the issue 😉 (even though it's a totally different code)

PydPiper commented 4 years ago

Thank you for submitting this, indeed this is a bug. Taking a look at your proposed solution now, but from the looks of it it's super clean!

PydPiper commented 4 years ago

incorporated in v1.44 thank you for submitting this!!