I am currently parsing multiple spread sheets and running into problems opening a few of them. The error that is produced directs me to the file "Cell\text.py" at the line that joins the snippets together in the content property.
workBook = openpyxl.load_workbook(filepath, True)
File "C:\Python34\lib\site-packages\openpyxl-2.3.1-py3.4.egg\openpyxl\reader\excel.py", line 191, in load_workbook
shared_strings = read_string_table(archive.read(strings_path))
File "C:\Python34\lib\site-packages\openpyxl-2.3.1-py3.4.egg\openpyxl\reader\strings.py", line 21, in read_string_table
text = Text.from_tree(node).content
File "C:\Python34\lib\site-packages\openpyxl-2.3.1-py3.4.egg\openpyxl\cell\text.py", line 182, in content
return "".join(snippets)
TypeError: sequence item 3: expected str instance, NoneType found
If I alter the code to have a check around the appending of the blocks in the formatted section as follows:
for block in self.formatted:
if(block.t is not None):
snippets.append(block.t)
It works fine, I was just wondering if there is some obvious problem with the excel sheet that I don't understand that someone could shed light on. I haven't rooted around the code for openpyxl so I am not sure what determines the contents of "self.formatted" but, My guess is that it is something caused by the merged cells in that area of the spread sheet.
EDIT
After reading your comments I dived a little deeper to see if there is any data I could share with you. I updated the Content property("Cell/Text.py") to output the data it was trying to join and searched the "sharedStrings.xml" for the xml data. The printed data was:
['“Replaced Data”', None]
After taking a look in the sharedStrings file the xml that contains this data is:
<si>
<r>
<t>“Replaced Data”</t>
</r>
<r>
<rPr>
<sz val="11"/>
<color rgb="FF008080"/>
<rFont val="Calibri"/>
<family val="2"/>
<scheme val="minor"/>
</rPr>
<t/>
</r>
</si>
This has nothing to do with merged cells but with the way text has been stored. Could you submit a bug report with a test file?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments