Search in sources :

Example 1 with CTShd

use of org.docx4j.wml.CTShd in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method setCellColor.

private void setCellColor(Tc tableCell, String color) {
    if (color != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTShd shd = new CTShd();
        shd.setFill(color);
        tableCellProperties.setShd(shd);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd)

Example 2 with CTShd

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

the class Docx4J_例子2 method createNormalCell.

public void createNormalCell(ObjectFactory factory, Tr tr, String content, RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor, String backgroudColor, boolean isHMerger, String mergeVal) {
    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);
    if (isHMerger) {
        HMerge merge = new HMerge();
        if (mergeVal != null) {
            merge.setVal(mergeVal);
        }
        tcPr.setHMerge(merge);
    } else {
        VMerge merge = new VMerge();
        if (mergeVal != null) {
            merge.setVal(mergeVal);
        }
        tcPr.setVMerge(merge);
    }
    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);
    tr.getContent().add(tableCell);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) TcPr(org.docx4j.wml.TcPr) HMerge(org.docx4j.wml.TcPrInner.HMerge) CTShd(org.docx4j.wml.CTShd) Text(org.docx4j.wml.Text) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Tc(org.docx4j.wml.Tc) VMerge(org.docx4j.wml.TcPrInner.VMerge)

Example 3 with CTShd

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

the class Docx4j_创建批注_S3_Test method setParagraphShdStyle.

// 段落底纹
public void setParagraphShdStyle(ObjectFactory factory, P p, boolean isShd, STShd shdValue, String shdColor) {
    if (isShd) {
        PPr ppr = factory.createPPr();
        CTShd shd = new CTShd();
        if (shdColor != null) {
            shd.setColor(shdColor);
        }
        if (shdValue != null) {
            shd.setVal(shdValue);
        }
        ppr.setShd(shd);
        p.setPPr(ppr);
    }
}
Also used : PPr(org.docx4j.wml.PPr) CTShd(org.docx4j.wml.CTShd)

Example 4 with CTShd

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

the class Docx4j_创建批注_S3_Test method getRPrStyle.

// 字体样式
public RPr getRPrStyle(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isItalic, boolean isStrike, boolean isUnderLine, UnderlineEnumeration underLineStyle, String underLineColor, boolean isHightLight, String hightLightValue, boolean isShd, STShd shdValue, String shdColor, CTVerticalAlignRun stRunEnum) {
    RPr rPr = factory.createRPr();
    RFonts rf = new RFonts();
    if (sTHint != null) {
        rf.setHint(sTHint);
    }
    if (fontFamily != null) {
        rf.setAscii(fontFamily);
        rf.setEastAsia(fontFamily);
        rf.setHAnsi(fontFamily);
    }
    rPr.setRFonts(rf);
    if (colorVal != null) {
        Color color = new Color();
        color.setVal(colorVal);
        rPr.setColor(color);
    }
    if (fontSize != null) {
        HpsMeasure sz = new HpsMeasure();
        sz.setVal(new BigInteger(fontSize));
        rPr.setSz(sz);
        rPr.setSzCs(sz);
    }
    BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
    if (isBlod) {
        rPr.setB(bdt);
    }
    if (isItalic) {
        rPr.setI(bdt);
    }
    if (isStrike) {
        rPr.setStrike(bdt);
    }
    if (isUnderLine) {
        U underline = new U();
        if (underLineStyle != null) {
            underline.setVal(underLineStyle);
        }
        if (underLineColor != null) {
            underline.setColor(underLineColor);
        }
        rPr.setU(underline);
    }
    if (isHightLight) {
        Highlight hight = new Highlight();
        hight.setVal(hightLightValue);
        rPr.setHighlight(hight);
    }
    if (isShd) {
        CTShd shd = new CTShd();
        if (shdColor != null) {
            shd.setColor(shdColor);
        }
        if (shdValue != null) {
            shd.setVal(shdValue);
        }
        rPr.setShd(shd);
    }
    if (stRunEnum != null) {
        rPr.setVertAlign(stRunEnum);
    }
    return rPr;
}
Also used : Highlight(org.docx4j.wml.Highlight) RPr(org.docx4j.wml.RPr) U(org.docx4j.wml.U) HpsMeasure(org.docx4j.wml.HpsMeasure) Color(org.docx4j.wml.Color) RFonts(org.docx4j.wml.RFonts) BigInteger(java.math.BigInteger) CTShd(org.docx4j.wml.CTShd) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Example 5 with CTShd

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

the class Docx4jStyle_S3 method setCellColor.

public void setCellColor(Tc tableCell, String color) {
    if (color != null) {
        TcPr tableCellProperties = tableCell.getTcPr();
        if (tableCellProperties == null) {
            tableCellProperties = new TcPr();
            tableCell.setTcPr(tableCellProperties);
        }
        CTShd shd = new CTShd();
        shd.setFill(color);
        tableCellProperties.setShd(shd);
    }
}
Also used : TcPr(org.docx4j.wml.TcPr) CTShd(org.docx4j.wml.CTShd)

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