There are different ways to represent a table with possibly merged
- In html, both vertically and horizontally merged cells are
represented by one cell only that has a colspan and rowspan
attribute. No dummy cells are used.
- In docx, horizontally merged cells are represented by one cell
with a gridSpan attribute; while vertically merged cells are
represented as a top cell containing the actual content and a series
of dummy cells having a vMerge tag with "continue" attribute.
- This table is a regular matrix, dummy cells are added for both
The algorithm is as follows,
- When a cell is added, its colspan is set. Even a dummy cell can have
a colspan, the same value as its upper has.
- When a new cell has a colspan greater than 1, the required extra
dummy cells are also added
- When a docx dummy cell is encountered (one with a vMerge
continue attribute), the rowspan is incremented in its upper
neighbors until a real cell is found.
A cell in the table holding its own content, too
If this is a real cell or only a placeholder. Vertically merged
cells are represented as a real cell on the top and dummy cell(s)
protected boolean dummy = false;
Create a dummy cell without content
logger.error("No content for row " + row + ", col " + col + "\n"
if (vm == null || vm.equals("continue"))
How many columns are merged into this cell
- 0 if none merged; 1 if two cells are merged so there is one
extra; etc. A dummy cell has the same extraCols value as its upper
If this is a real cell, increment rowspan; if this is a dummy,
propagate the call to the cell upwards
s += "(" + row + "," + col + ")";