Search in sources :

Example 6 with CTVerticalJc

use of org.docx4j.wml.CTVerticalJc 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 CTVerticalJc

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

the class Docx4jStyle_S3 method setVerticalAlignment.

public void setVerticalAlignment(Tc tableCell, STVerticalJc align) {
    if (align != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTVerticalJc valign = new CTVerticalJc();
        valign.setVal(align);
        tableCellProperties.setVAlign(valign);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTVerticalJc(org.docx4j.wml.CTVerticalJc)

Aggregations

CTVerticalJc (org.docx4j.wml.CTVerticalJc)7 TcPr (org.docx4j.wml.TcPr)6 CTShd (org.docx4j.wml.CTShd)3 P (org.docx4j.wml.P)3 R (org.docx4j.wml.R)3 Tc (org.docx4j.wml.Tc)3 Text (org.docx4j.wml.Text)3 BigInteger (java.math.BigInteger)1 PPr (org.docx4j.wml.PPr)1 Spacing (org.docx4j.wml.PPrBase.Spacing)1 SectPr (org.docx4j.wml.SectPr)1 HMerge (org.docx4j.wml.TcPrInner.HMerge)1 VMerge (org.docx4j.wml.TcPrInner.VMerge)1