-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
I need to read data from the table in docx, but the loop raises IndexError. I tried to use iter_unique_cells method that i found, but it didnt solve the problem.Any help would be greatly appreciated !
another_broken_table.docx
def iter_unique_cells(row):
"""Generate cells in *row* skipping empty grid cells."""
prior_tc = None
for cell in row.cells:
this_tc = cell._tc
if this_tc is prior_tc:
continue
prior_tc = this_tc
yield cell
document = Document('another_broken_table.docx')
tables = document.tables
for table in tables:
for row in table.rows:
for cell in iter_unique_cells(row):
pass
Traceback (most recent call last):
File "d:/test.py", line 94, in <module>
xml_string = loop_tables(tables)
File "d:/test.py", line 52, in loop_tables
for cell in iter_unique_cells(row):
File "d:/test.py", line 12, in iter_unique_cells
for cell in row.cells:
File "D:\Python\Python36-32\lib\site-packages\docx\table.py", line 401, in cells
return tuple(self.table.row_cells(self._index))
File "D:\Python\Python36-32\lib\site-packages\docx\table.py", line 106, in row_cells
return self._cells[start:end]
File "D:\Python\Python36-32\lib\site-packages\docx\table.py", line 173, in _cells
cells.append(cells[-col_count])
IndexError: list index out of range
hanshou101
Metadata
Metadata
Assignees
Labels
No labels