Index error when reading table
See original GitHub issueI 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to Fix IndexError in Python - Rollbar
The IndexError in Python occurs when an item from a list is attempted to be accessed that is outside the index range of...
Read more >How to solve "IndexError: list index out of range" error when ...
I hope it makes sense.. I am currently working on a populating a postgres database where I have this loop which iterates along...
Read more >How to debug list index out of range error in python? - Flexiple
So let us first understand how indexes work and then look at the solutions for the list index out of range error. Lists...
Read more >Error (The changes you requested to the table were not ...
The table may not have any relationships or any indexes. Cause. This problem occurs when the Autonumber field has been incorrectly seeded.
Read more >mysqlcheck unexpectedly causes table to be marked as corrupt
2020-11-24 10:01:44 44 [ERROR] InnoDB: Record in index ... [ERROR] Got error 128 when reading table './schema/tablex' [ERROR] Got error 180 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

What does
print(row._tr.xml)output for the offending row?You might also try:
There is a problem with this solution. It solves one problem while causing another. When you use this fix, merged cells are no longer unmerged during the parsing process. Without unmerging the cells, you will never be able to reproduce your table with the output data because your columns will no longer line up when you try to reproduce the table. Is there a way to fix this
IndexErrorwithout causing this problem?