Ejemplo n.º 1
0
  /**
   * Sets style of paragraph
   *
   * @param paragraph Paragraph to style
   * @param styleName Style name
   */
  private void setStyle(ContentAccessor element, String styleName) {
    if (element instanceof P) {
      PPrBase.PStyle style = objectFactory.createPPrBasePStyle();
      style.setVal(styleName);

      PPr ppr = objectFactory.createPPr();
      ppr.setPStyle(style);
      ((P) element).setPPr(ppr);
    } else if (element instanceof Tbl) {
      TblPr.TblStyle style = objectFactory.createCTTblPrBaseTblStyle();
      style.setVal(styleName);

      TblPr tpr = objectFactory.createTblPr();
      CTTblLook tblLook = objectFactory.createCTTblLook();
      tblLook.setFirstColumn(STOnOff.FALSE);
      tblLook.setFirstRow(STOnOff.TRUE);
      tblLook.setLastColumn(STOnOff.FALSE);
      tblLook.setLastRow(STOnOff.FALSE);
      tblLook.setNoHBand(STOnOff.FALSE);
      tblLook.setNoVBand(STOnOff.TRUE);
      tpr.setTblLook(tblLook);

      tpr.setTblStyle(style);
      ((Tbl) element).setTblPr(tpr);
    }
  }
Ejemplo n.º 2
0
  /**
   * Create a paragraph containing the string simpleText, styled using the specified style (up to
   * user to ensure it is a paragraph style) without adding it to the document.
   *
   * @param styleId
   * @param text
   * @return
   */
  public org.docx4j.wml.P createStyledParagraphOfText(String styleId, String text) {

    org.docx4j.wml.P p = createParagraphOfText(text);

    StyleDefinitionsPart styleDefinitionsPart = this.getStyleDefinitionsPart();

    if (getPropertyResolver().activateStyle(styleId)) {
      // Style is available
      org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
      org.docx4j.wml.PPr pPr = factory.createPPr();
      p.setPPr(pPr);
      org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
      pPr.setPStyle(pStyle);
      pStyle.setVal(styleId);
    }

    return p;
  }