You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to modify tables in a Word document using python-docx, an IndexError occurs if the table contains merged cells. Specifically, the error appears when trying to access certain rows or cells in tables that have vertical or horizontal cell merging, which leads to an IndexError: list index out of range.
Steps to Reproduce:
Load a Word document that contains a table with merged cells (either vertically or horizontally).
Attempt to access and edit cells within the table using the python-docx library, specifically targeting merged cells.
The library raises an IndexError: list index out of range when trying to access these merged cells.
Expected Behavior:
The library should handle merged cells appropriately, allowing access to their content and permitting modifications without raising an error.
Observed Behavior:
The table structure breaks when attempting to access merged cells, leading to an IndexError. This occurs because python-docx struggles to handle complex table layouts with merged cells or rows.
Traceback:
python
Copy code
IndexError: list index out of range
File ".../docx/table.py", line 401, in _Row.cells
return tuple(self.table.row_cells(self._index))
File ".../docx/table.py", line 106, in Table.row_cells
return self._cells[start:end]
File ".../docx/table.py", line 173, in Table._cells
cells.append(cells[-col_count])
IndexError: list index out of range
Additional Notes:
The issue was specifically encountered while trying to modify cells containing the placeholder text "Add answer here" in a table with merged rows. Other standard tables in the document could be edited without issues.
The merged cells seem to affect the way python-docx indexes table rows, causing the list index error.
Environment:
python-docx version: [Please specify the version used]
Python version: [Please specify your Python version]
Operating System: [e.g., Windows 10, macOS, etc.]
The text was updated successfully, but these errors were encountered:
When attempting to modify tables in a Word document using python-docx, an IndexError occurs if the table contains merged cells. Specifically, the error appears when trying to access certain rows or cells in tables that have vertical or horizontal cell merging, which leads to an IndexError: list index out of range.
Steps to Reproduce:
Load a Word document that contains a table with merged cells (either vertically or horizontally).
Attempt to access and edit cells within the table using the python-docx library, specifically targeting merged cells.
The library raises an IndexError: list index out of range when trying to access these merged cells.
Expected Behavior:
The library should handle merged cells appropriately, allowing access to their content and permitting modifications without raising an error.
Observed Behavior:
The table structure breaks when attempting to access merged cells, leading to an IndexError. This occurs because python-docx struggles to handle complex table layouts with merged cells or rows.
Traceback:
python
Copy code
IndexError: list index out of range
File ".../docx/table.py", line 401, in _Row.cells
return tuple(self.table.row_cells(self._index))
File ".../docx/table.py", line 106, in Table.row_cells
return self._cells[start:end]
File ".../docx/table.py", line 173, in Table._cells
cells.append(cells[-col_count])
IndexError: list index out of range
Additional Notes:
The issue was specifically encountered while trying to modify cells containing the placeholder text "Add answer here" in a table with merged rows. Other standard tables in the document could be edited without issues.
The merged cells seem to affect the way python-docx indexes table rows, causing the list index error.
Environment:
python-docx version: [Please specify the version used]
Python version: [Please specify your Python version]
Operating System: [e.g., Windows 10, macOS, etc.]
The text was updated successfully, but these errors were encountered: