Search in sources :

Example 6 with Spacing

use of org.docx4j.wml.PPrBase.Spacing in project docx4j-template by vindell.

the class Docx4J_简单例子2 method addTableCell.

// 新增单元格
public void addTableCell(ObjectFactory factory, WordprocessingMLPackage wordMLPackage, Tr tableRow, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor) {
    Tc tableCell = factory.createTc();
    P p = factory.createP();
    setParagraphAlign(factory, p, jcEnumeration);
    Text t = factory.createText();
    t.setValue(content);
    R run = factory.createR();
    // 设置表格内容字体样式
    run.setRPr(rpr);
    TcPr tcPr = tableCell.getTcPr();
    if (tcPr == null) {
        tcPr = factory.createTcPr();
    }
    CTVerticalJc valign = factory.createCTVerticalJc();
    valign.setVal(STVerticalJc.CENTER);
    tcPr.setVAlign(valign);
    run.getContent().add(t);
    p.getContent().add(run);
    PPr ppr = p.getPPr();
    if (ppr == null) {
        ppr = factory.createPPr();
    }
    // 设置段后距离
    Spacing spacing = new Spacing();
    spacing.setAfter(new BigInteger("0"));
    spacing.setLineRule(STLineSpacingRule.AUTO);
    ppr.setSpacing(spacing);
    p.setPPr(ppr);
    tableCell.getContent().add(p);
    if (hasBgColor) {
        CTShd shd = tcPr.getShd();
        if (shd == null) {
            shd = factory.createCTShd();
        }
        shd.setColor("auto");
        shd.setFill(backgroudColor);
        tcPr.setShd(shd);
        tableCell.setTcPr(tcPr);
    }
    tableRow.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) TcPr(org.docx4j.wml.TcPr) BigInteger(java.math.BigInteger) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) Spacing(org.docx4j.wml.PPrBase.Spacing) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc)

Example 7 with Spacing

use of org.docx4j.wml.PPrBase.Spacing in project docx4j-template by vindell.

the class Docx4j_创建批注_S3_Test method setParagraphSpacing.

// 段落间距
public void setParagraphSpacing(ObjectFactory factory, P p, boolean isSpace, String before, String after, boolean isLines, String beforeLines, String afterLines, boolean isLineRule, String lineValue, STLineSpacingRule sTLineSpacingRule) {
    PPr pPr = p.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Spacing spacing = new Spacing();
    if (isSpace) {
        if (before != null) {
            // 段前磅数
            spacing.setBefore(new BigInteger(before));
        }
        if (after != null) {
            // 段后磅数
            spacing.setAfter(new BigInteger(after));
        }
    }
    if (isLines) {
        if (beforeLines != null) {
            // 段前行数
            spacing.setBeforeLines(new BigInteger(beforeLines));
        }
        if (afterLines != null) {
            // 段后行数
            spacing.setAfterLines(new BigInteger(afterLines));
        }
    }
    if (isLineRule) {
        if (lineValue != null) {
            spacing.setLine(new BigInteger(lineValue));
        }
        spacing.setLineRule(sTLineSpacingRule);
    }
    pPr.setSpacing(spacing);
    p.setPPr(pPr);
}
Also used : PPr(org.docx4j.wml.PPr) BigInteger(java.math.BigInteger) Spacing(org.docx4j.wml.PPrBase.Spacing)

Aggregations

Spacing (org.docx4j.wml.PPrBase.Spacing)7 BigInteger (java.math.BigInteger)5 PPr (org.docx4j.wml.PPr)5 CTVerticalJc (org.docx4j.wml.CTVerticalJc)3 Jc (org.docx4j.wml.Jc)2 STVerticalJc (org.docx4j.wml.STVerticalJc)2 CTShd (org.docx4j.wml.CTShd)1 P (org.docx4j.wml.P)1 PStyle (org.docx4j.wml.PPrBase.PStyle)1 R (org.docx4j.wml.R)1 Tc (org.docx4j.wml.Tc)1 TcPr (org.docx4j.wml.TcPr)1 Text (org.docx4j.wml.Text)1