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.
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.
This model captures: - whether the table layout is fixed or auto (Word usually does auto) - whether conflict resolution is required on cell borders (Word usually does conflict resolution)
Author:
Adam Schmideg, Alberto Zerolo, Jason Harrop
  • Field Details

    • rows

      protected java.util.List<TableModelRow> 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

      protected Style effectiveTableStyle
    • tblPr

      protected TblPr tblPr
      Table properties are represented using the docx model.
    • tblGrid

      protected TblGrid tblGrid
    • tbl

      protected Tbl tbl
  • Constructor Details

    • TableModel

      public TableModel()
  • Method Details

    • getStyleId

      public java.lang.String getStyleId()
      Returns:
      the table's style, if any
    • getEffectiveTableStyle

      public Style getEffectiveTableStyle()
      Returns:
      the table's effective Style
    • getTblPr

      public TblPr getTblPr()
      Returns:
      the w:tblPr
    • getTblGrid

      public TblGrid 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

      public void startRow​(Tr tr)
    • addCell

      public void addCell​(Tc tc)
      Add a new cell to this table
    • addDummyCell

      protected void addDummyCell​(int colSpan, boolean isBefore, boolean isAfter)
    • addCell

      protected void addCell​(TableModelCell cell)
    • getCell

      public TableModelCell getCell​(int row, int col)
    • getColName

      public java.lang.String getColName​(int col)
      Returns:
      "colX" where X is a 1-based index
    • getColCount

      public int getColCount()
    • getRows

      public java.util.List<TableModelRow> getRows()
    • getHeaderMaxRow

      public int getHeaderMaxRow()
    • build

      public void build​(Tbl tbl)
    • handleRow

      protected void handleRow​(Tr tr, int r)
    • isHeaderRow

      protected boolean isHeaderRow​(Tr tr)
    • getGridAfter

      protected int getGridAfter​(Tr tr)
    • getGridBefore

      protected int getGridBefore​(Tr tr)
    • 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)