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 classTableModel.TrFinder -
Field Summary
Fields Modifier and Type Field Description protected intcolprotected booleandrawTableBorderprotected StyleeffectiveTableStyleprotected intheaderMaxRowprotected introwprotected java.util.List<TableModelRow>rowsA list of rowsprotected java.lang.StringstyleIdprotected Tbltblprotected TblGridtblGridprotected TblPrtblPrTable properties are represented using the docx model.protected intwidth -
Constructor Summary
Constructors Constructor Description TableModel() -
Method Summary
Modifier and Type Method Description protected voidaddCell(TableModelCell cell)voidaddCell(Tc tc)Add a new cell to this tableprotected voidaddDummyCell(int colSpan, boolean isBefore, boolean isAfter)voidbuild(Tbl tbl)protected intcalcTableWidth()java.lang.StringdebugStr()TableModelCellgetCell(int row, int col)intgetColCount()java.lang.StringgetColName(int col)StylegetEffectiveTableStyle()protected javax.xml.bind.JAXBElement<?>getElement(java.util.List<javax.xml.bind.JAXBElement<?>> cnfStyleOrDivIdOrGridBefore, java.lang.String localName)protected intgetGridAfter(Tr tr)protected intgetGridBefore(Tr tr)intgetHeaderMaxRow()java.util.List<TableModelRow>getRows()java.lang.StringgetStyleId()intgetTableWidth()TblGridgetTblGrid()TblPrgetTblPr()protected voidhandleRow(Tr tr, int r)booleanisBorderConflictResolutionRequired()If borderConflictResolutionRequired is required, we need to set this explicitly, because in CSS, 'separate' is the default.booleanisDrawTableBorders()protected booleanisHeaderRow(Tr tr)voidresetIndexes()Reset row and col.voidsetBorderConflictResolutionRequired(boolean borderConflictResolutionRequired)voidstartRow(Tr tr)
-
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 javax.xml.bind.JAXBElement<?> getElement(java.util.List<javax.xml.bind.JAXBElement<?>> cnfStyleOrDivIdOrGridBefore, java.lang.String localName) -
calcTableWidth
protected int calcTableWidth() -
debugStr
public java.lang.String debugStr() -
setBorderConflictResolutionRequired
public void setBorderConflictResolutionRequired(boolean borderConflictResolutionRequired)
-