Search in sources :

Example 6 with CTShd

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

the class Docx4j_工具类_S3_Test method setParagraphShdStyle.

/**
 * @Description: 设置段落底纹(对整段文字起作用)
 */
public void setParagraphShdStyle(P p, STShd shdType, String shdColor) {
    PPr ppr = getPPr(p);
    CTShd ctShd = ppr.getShd();
    if (ctShd == null) {
        ctShd = new CTShd();
    }
    if (StringUtils.isNotBlank(shdColor)) {
        ctShd.setColor(shdColor);
    }
    if (shdType != null) {
        ctShd.setVal(shdType);
    }
    ppr.setShd(ctShd);
}
Also used : PPr(org.docx4j.wml.PPr) CTShd(org.docx4j.wml.CTShd)

Example 7 with CTShd

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

the class Docx4j_工具类_S3_Test method addRPrShdStyle.

/**
 * @Description: 设置底纹
 */
public void addRPrShdStyle(RPr runProperties, STShd shdtype) {
    if (shdtype != null) {
        CTShd shd = new CTShd();
        shd.setVal(shdtype);
        runProperties.setShd(shd);
    }
}
Also used : CTShd(org.docx4j.wml.CTShd)

Example 8 with CTShd

use of org.docx4j.wml.CTShd 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();
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    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);
    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) TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc)

Example 9 with CTShd

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

the class Docx4J_简单例子 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);
    run.getContent().add(t);
    p.getContent().add(run);
    tableCell.getContent().add(p);
    if (hasBgColor) {
        TcPr tcPr = tableCell.getTcPr();
        if (tcPr == null) {
            tcPr = factory.createTcPr();
        }
        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) TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) Tc(org.docx4j.wml.Tc)

Example 10 with CTShd

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

Aggregations

CTShd (org.docx4j.wml.CTShd)10 TcPr (org.docx4j.wml.TcPr)6 P (org.docx4j.wml.P)4 R (org.docx4j.wml.R)4 Tc (org.docx4j.wml.Tc)4 Text (org.docx4j.wml.Text)4 CTVerticalJc (org.docx4j.wml.CTVerticalJc)3 PPr (org.docx4j.wml.PPr)3 BigInteger (java.math.BigInteger)2 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)1 Color (org.docx4j.wml.Color)1 Highlight (org.docx4j.wml.Highlight)1 HpsMeasure (org.docx4j.wml.HpsMeasure)1 Spacing (org.docx4j.wml.PPrBase.Spacing)1 RFonts (org.docx4j.wml.RFonts)1 RPr (org.docx4j.wml.RPr)1 HMerge (org.docx4j.wml.TcPrInner.HMerge)1 VMerge (org.docx4j.wml.TcPrInner.VMerge)1 U (org.docx4j.wml.U)1