Cell.java

  1. package org.docascode.api.core.office.table;

  2. import org.docascode.api.core.office.ParagraphFormat;
  3. import org.docx4j.jaxb.Context;
  4. import org.docx4j.wml.*;

  5. public class Cell {
  6.     private String text;

  7.     private ParagraphFormat paragraphFormat;

  8.     public Cell setText(String text){
  9.         this.text = text;
  10.         return this;
  11.     }

  12.     public Cell setParagraphFormat(ParagraphFormat paragraphFormat){
  13.         if (this.paragraphFormat == null){
  14.             this.paragraphFormat = paragraphFormat;
  15.         }
  16.         return this;
  17.     }

  18.     P toP(){
  19.         org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
  20.         P p = factory.createP();
  21.         if (this.paragraphFormat != null){
  22.             p.setPPr(this.paragraphFormat.toPPr());
  23.         }
  24.         R r = factory.createR();
  25.         p.getContent().add(r);
  26.         Text t = factory.createText();
  27.         t.setValue(this.text);
  28.         r.getContent().add(t);
  29.         return p;
  30.     }
  31. }