Package org.docx4j.model.table
Class TableModel
java.lang.Object
org.docx4j.model.table.TableModel
- Direct Known Subclasses:
AbstractTableWriterModel
public class TableModel
extends java.lang.Object
There are different ways to represent a table with possibly merged
cells.
- 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.
- In the model used in this class, we use a regular matrix; dummy cells are added for both merge directions.
- 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.
- Author:
- Adam Schmideg, Alberto Zerolo, Jason Harrop
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableModel.TrFinder
-
Field Summary
Fields Modifier and Type Field Description protected int
col
protected boolean
drawTableBorder
protected Style
effectiveTableStyle
protected int
headerMaxRow
protected int
row
protected java.util.List<TableModelRow>
rows
A list of rowsprotected java.lang.String
styleId
protected Tbl
tbl
protected TblGrid
tblGrid
protected TblPr
tblPr
Table properties are represented using the docx model.protected int
width
-
Constructor Summary
Constructors Constructor Description TableModel()
-
Method Summary
Modifier and Type Method Description protected void
addCell(TableModelCell cell)
void
addCell(Tc tc)
Add a new cell to this tableprotected void
addDummyCell(int colSpan, boolean isBefore, boolean isAfter)
void
build(Tbl tbl)
protected int
calcTableWidth()
java.lang.String
debugStr()
TableModelCell
getCell(int row, int col)
int
getColCount()
java.lang.String
getColName(int col)
Style
getEffectiveTableStyle()
protected jakarta.xml.bind.JAXBElement<?>
getElement(java.util.List<jakarta.xml.bind.JAXBElement<?>> cnfStyleOrDivIdOrGridBefore, java.lang.String localName)
protected int
getGridAfter(Tr tr)
protected int
getGridBefore(Tr tr)
int
getHeaderMaxRow()
java.util.List<TableModelRow>
getRows()
java.lang.String
getStyleId()
int
getTableWidth()
TblGrid
getTblGrid()
TblPr
getTblPr()
protected void
handleRow(Tr tr, int r)
boolean
isBorderConflictResolutionRequired()
If borderConflictResolutionRequired is required, we need to set this explicitly, because in CSS, 'separate' is the default.boolean
isDrawTableBorders()
protected boolean
isHeaderRow(Tr tr)
void
resetIndexes()
Reset row and col.void
setBorderConflictResolutionRequired(boolean borderConflictResolutionRequired)
void
startRow(Tr tr)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
rows
A list of rows -
headerMaxRow
protected int headerMaxRow -
row
protected int row -
col
protected int col -
width
protected int width -
drawTableBorder
protected boolean drawTableBorder -
styleId
protected java.lang.String styleId -
effectiveTableStyle
-
tblPr
Table properties are represented using the docx model. -
tblGrid
-
tbl
-
-
Constructor Details
-
TableModel
public TableModel()
-
-
Method Details
-
getStyleId
public java.lang.String getStyleId()- Returns:
- the table's style, if any
-
getEffectiveTableStyle
- Returns:
- the table's effective Style
-
getTblPr
- Returns:
- the w:tblPr
-
getTblGrid
- Returns:
- the w:tblGrid
-
isBorderConflictResolutionRequired
public boolean isBorderConflictResolutionRequired()If borderConflictResolutionRequired is required, we need to set this explicitly, because in CSS, 'separate' is the default. We need to avoid incorrectly overruling an inherited value (ie where TblCellSpacing is set), so we do borderConflictResolutionRequired here, as an explicit \@style value, rather than that in conjunction with \@class.- Returns:
- borderConflictResolutionRequired
-
isDrawTableBorders
public boolean isDrawTableBorders() -
getTableWidth
public int getTableWidth() -
resetIndexes
public void resetIndexes()Reset row and col. -
startRow
-
addCell
Add a new cell to this table -
addDummyCell
protected void addDummyCell(int colSpan, boolean isBefore, boolean isAfter) -
addCell
-
getCell
-
getColName
public java.lang.String getColName(int col)- Returns:
- "colX" where X is a 1-based index
-
getColCount
public int getColCount() -
getRows
-
getHeaderMaxRow
public int getHeaderMaxRow() -
build
-
handleRow
-
isHeaderRow
-
getGridAfter
-
getGridBefore
-
getElement
protected jakarta.xml.bind.JAXBElement<?> getElement(java.util.List<jakarta.xml.bind.JAXBElement<?>> cnfStyleOrDivIdOrGridBefore, java.lang.String localName) -
calcTableWidth
protected int calcTableWidth() -
debugStr
public java.lang.String debugStr() -
setBorderConflictResolutionRequired
public void setBorderConflictResolutionRequired(boolean borderConflictResolutionRequired)
-