Can't save and reopen xlsx file with comments with version 2.3.0
Created originally on Bitbucket by SleepProgger
I tried to load, change and save an xlsx file i downloaded from google spreadsheet and got this error on reloading the file:
#!python
Traceback (most recent call last):
File "D:\workspace\python\SantasImp\test.py", line 15, in <module>
book = load_workbook(filename, keep_vba=True, data_only=True, guess_types=True)
File "C:\Program Files (x86)\python\lib\site-packages\openpyxl\reader\excel.py", line 241, in load_workbook
read_comments(new_ws, archive.read(comments_file))
File "C:\Program Files (x86)\python\lib\site-packages\openpyxl\reader\comments.py", line 31, in read_comments
runtext = ''.join([t.text for t in run.findall('{%s}t' % SHEET_MAIN_NS)])
TypeError: sequence item 0: expected string, NoneType found
After some digging around i realized this happens when using comments. Removing the comments before saving solves this issue.
Test case:
#!python
filename = 'test.xlsx'
book = load_workbook(filename, keep_vba=True)
# clean comments
sheet = book.active
for row in sheet.rows:
for cell in row: cell.comment = None
book.save("test2.xlsx")
filename = 'test2.xlsx'
book = load_workbook(filename, keep_vba=True)
I added my test xlsx file generated by google spreadsheets.
Thanks for this great piece of software, SleepProgger
Attachments: test.xlsx