Skip to content

Commit

Permalink
Merge pull request #19 from ctxis/master
Browse files Browse the repository at this point in the history
Fix error when trying to access the Row object in a table with vertically merged cells
  • Loading branch information
orf authored Nov 1, 2018
2 parents 8c6633c + 54aa920 commit 5df6448
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions wordinserter/renderers/com.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,16 @@ def table(self, op: Table):
]

processed_cells = set()
has_rowspan = False

# Handling merged cells is a bitch. We do it by finding the max dimensions of the table (the max sum of all
# colspans in a row) then creating a table with those dimensions.
# We then enumerate through each cell in each row, and find the corresponding word cell (the actual table cell)

for row_index, row in enumerate(op):
# Store the row object for later use
row.render.row_object = table.Rows(row_index+1)
# Store the row object for later use. This cannot be used if the table has vertically merged cells
row.render.row_object = table.Rows(row_index+1) if not has_rowspan else None

# Loop through each row and extract the corresponding Row object from Word
row_cells = cell_mapping[row_index]

Expand Down Expand Up @@ -451,6 +453,7 @@ def table(self, op: Table):

if cell.rowspan > 1:
# If the cell has a rowspan things get tricky.
has_rowspan = True
if cell.colspan > 1:
# If it's got a colspan we need to go down the rows below it and merge those cells into
# a single cell, pretty much the same as above.
Expand Down

0 comments on commit 5df6448

Please sign in to comment.