PydPiper / pylightxl

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

a Suggestion in readxl_get_sharedStrings #64

Closed wangdaye078 closed 2 years ago

wangdaye078 commented 2 years ago

Pylightxl Version:1.58 Python Version:3.8

Suggestion for fix: in def readxl_get_sharedStrings(fn)

text = ''.join([tag.text for tag in tag_t]) maybe chang to: text = ''.join([tag.text for tag in tag_t if tag.text])

because some time tag.text is None

PydPiper commented 2 years ago

@newhying thank you for considering using pylightxl for your project. Can you post the full traceback where this was an issue. The following line should be sufficient to handle tags

    for i, tag_si in enumerate(root.findall('./default:si', ns)):
        tag_t = tag_si.findall('./default:r//default:t', ns)
        if tag_t:
            text = ''.join([tag.text for tag in tag_t])
        else:
            text = tag_si.findall('./default:t', ns)[0].text
        sharedStrings.update({i: text})
wangdaye078 commented 2 years ago

Traceback (most recent call last): ......................... t_driver.workbook = pylightxl.readxl(filename) File "d:\python\python38\lib\site-packages\pylightxl\pylightxl.py", line 129, in readxl sharedString = readxl_get_sharedStrings(fn) File "d:\python\python38\lib\site-packages\pylightxl\pylightxl.py", line 319, in readxl_get_sharedStrings text = ''.join([tag.text for tag in tag_t]) TypeError: sequence item 1: expected str instance, NoneType found

open sharedStrings.xml find this

<si>
    <r>
        <t>lvUpNum2_i</t>
    </r>
    <r>
        <rPr>
            <sz val="10"/>
            <color indexed="8"/>
            <rFont val="宋体"/>
            <family val="3"/>
            <charset val="134"/>
        </rPr>
        <t/>
    </r>
</si>
PydPiper commented 2 years ago

I see, great thanks for submitting this. This should be an easy update. I'll make the change now and once the other issue is also close we'll release a new version.

PydPiper commented 2 years ago

will be released in v1.59 later today, thanks for submitting this

yohanboniface commented 2 years ago

Hey @PydPiper any chance to get a new release ? Thanks :)

PydPiper commented 2 years ago

@yohanboniface hey yes sorry ive been tied up with school. I’ll take a look at releasing a new version today after work. Thanks for the reminder!

PydPiper commented 2 years ago

@yohanboniface v1.59 was released with this update. Thank you again for the reminder!

yohanboniface commented 2 years ago

Thanks @PydPiper :)