First, I have read Parsing a table with rowspan and colspan. I even answered the question. Please read before you mark this as duplicate.
Important to note, that Martijn Pieters solution does not account for the case of cells having rowspan and colspan attribute simultaneosly. E.g.
A
B
C
D
E
E
C
C
E
C
C
C
C
C
This table renders to
+-----------+---+---+---+
| A | B | C | D |
| +---+---+---+
| | E |
| +---+---+---+
| | E | C | C |
+---+---+---+---+---+---+
| E | C | C | C | C | C |
+---+---+---+---+---+---+
but if we apply the function we get
[['A', 'A', 'A', 'B', 'C', 'D'],
['A', 'E', 'E', 'E', None, None],
['A', 'E', 'C', 'C', None, None],
['E', 'C', 'C', 'C', 'C', 'C']]
There may be some edge cases, but extending rowspan bookkeeping to cells in the product
of rowspan and colspan, i.e.
for drow, dcol in product(range(rowspan), range(colspan)):
try:
table[row + drow][col + dcol] = value
rowspans[col + dcol] = rowspan
except IndexError:
# rowspan or colspan outside the confines of the table
pass
seems to work on examples in this thread, and for the table above it will output
[['A', 'A', 'A', 'B', 'C', 'D'],
['A', 'A', 'A', 'E', 'E', 'E'],
['A', 'A', 'A', 'E', 'C', 'C'],
['E', 'C', 'C', 'C', 'C', 'C']]