Class AbstractTableWriterModel

java.lang.Object
org.docx4j.model.table.TableModel
org.docx4j.convert.out.common.writer.AbstractTableWriterModel

public class AbstractTableWriterModel extends TableModel
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.
  • This table is 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)
  • Field Details

    • log

      private static final org.slf4j.Logger log
  • Constructor Details

    • AbstractTableWriterModel

      public AbstractTableWriterModel()
  • Method Details

    • addCell

      public void addCell(Tc tc, Node content)
      Add a new cell to this table and copy processed content of tc to it.
    • addRow

      protected void addRow(AbstractTableWriterModelCell cell)
    • build

      public void build(AbstractWmlConversionContext conversionContext, Object node, Node content) throws TransformerException
      Build a table representation from a tbl instance. Remember to set wordMLPackage before using this method!
      Throws:
      TransformerException
    • ensureFoTableBody

      private void ensureFoTableBody(List<Tr> rows)
      "fo:table" content model is: (marker*,table-column*,table-header?,table-footer?,table-body+) ie table-header (if any) must precede table-body The first requirement is that there is a table-body. Since the docx format doesn't have any equivalent to table-footer, we can always treat the last row as table-body. The second requirement is that there is no table-header after table-body. We could either treat each t-h after a t-b as t-b, or we could treat all t-b before t-h as t-h. If the docx has normal rows before the a t-h row, the user should split the table into two. Since they can do that, we'll treat all rows before last t-h row as t-h rows
    • handleRow

      protected void handleRow(NodeList cellContents, Tr tr, int r)
    • getTc

      private Node getTc(Node wtrNode, int wanted, AbstractTableWriterModel.IntRef current)
      The tc could be inside something else, so find it recursively.
      Parameters:
      wtrNode -
      wanted -
      current -
      Returns: