Search in sources :

Example 6 with R

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

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

the class Docx4J_例子2 method addPageTextField.

private void addPageTextField(ObjectFactory factory, P paragraph, String value) {
    R run = factory.createR();
    Text txt = new Text();
    txt.setSpace("preserve");
    txt.setValue(value);
    run.getContent().add(txt);
    paragraph.getContent().add(run);
}
Also used : R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 8 with R

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

the class Docx4J_例子2 method createFooterWithPageNr.

public Ftr createFooterWithPageNr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception {
    Ftr ftr = factory.createFtr();
    P paragraph = factory.createP();
    RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA, false, false, false, false);
    R run = factory.createR();
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    addPageTextField(factory, paragraph, "第");
    addFieldBegin(factory, paragraph);
    addPageNumberField(factory, paragraph);
    addFieldEnd(factory, paragraph);
    addPageTextField(factory, paragraph, "页");
    addPageTextField(factory, paragraph, " 总共");
    addFieldBegin(factory, paragraph);
    addTotalPageNumberField(factory, paragraph);
    addFieldEnd(factory, paragraph);
    addPageTextField(factory, paragraph, "页");
    setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    PPr pPr = paragraph.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    if (isUnderLine) {
        PBdr pBdr = pPr.getPBdr();
        if (pBdr == null) {
            pBdr = factory.createPPrBasePBdr();
        }
        CTBorder value = new CTBorder();
        value.setVal(STBorder.SINGLE);
        value.setColor("000000");
        value.setSpace(new BigInteger("0"));
        value.setSz(new BigInteger(underLineSz));
        pBdr.setBetween(value);
        pPr.setPBdr(pBdr);
        paragraph.setPPr(pPr);
    }
    ftr.getContent().add(paragraph);
    if (isUnderLine) {
        ftr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration));
    }
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) Ftr(org.docx4j.wml.Ftr) RPr(org.docx4j.wml.RPr) ParaRPr(org.docx4j.wml.ParaRPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger)

Example 9 with R

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

the class Docx4J_例子2 method getTextFtr.

public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration) throws Exception {
    Ftr ftr = factory.createFtr();
    P footerP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    footerP.getContent().add(run);
    PPr pPr = footerP.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    footerP.setPPr(pPr);
    setParagraphSpacing(factory, footerP, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    if (isUnderLine) {
        PBdr pBdr = pPr.getPBdr();
        if (pBdr == null) {
            pBdr = factory.createPPrBasePBdr();
        }
        CTBorder value = new CTBorder();
        value.setVal(STBorder.SINGLE);
        value.setColor("000000");
        value.setSpace(new BigInteger("0"));
        value.setSz(new BigInteger(underLineSz));
        pBdr.setBetween(value);
        pPr.setPBdr(pBdr);
        footerP.setPPr(pPr);
    }
    ftr.getContent().add(footerP);
    if (isUnderLine) {
        ftr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, underLineSz, jcEnumeration));
    }
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) Ftr(org.docx4j.wml.Ftr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger) Text(org.docx4j.wml.Text)

Example 10 with R

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

the class Docx4J_例子2 method createHeaderBlankP.

public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, String underLineSz, JcEnumeration jcEnumeration) throws Exception {
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    PPr pPr = p.getPPr();
    if (pPr == null) {
        pPr = factory.createPPr();
    }
    Jc jc = pPr.getJc();
    if (jc == null) {
        jc = new Jc();
    }
    jc.setVal(jcEnumeration);
    pPr.setJc(jc);
    PBdr pBdr = pPr.getPBdr();
    if (pBdr == null) {
        pBdr = factory.createPPrBasePBdr();
    }
    CTBorder value = new CTBorder();
    value.setVal(STBorder.SINGLE);
    value.setColor("000000");
    value.setSpace(new BigInteger("0"));
    value.setSz(new BigInteger(underLineSz));
    pBdr.setBetween(value);
    pPr.setPBdr(pBdr);
    p.setPPr(pPr);
    setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null, null, true, "240", STLineSpacingRule.AUTO);
    return p;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) PBdr(org.docx4j.wml.PPrBase.PBdr) CTBorder(org.docx4j.wml.CTBorder) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) BigInteger(java.math.BigInteger)

Aggregations

R (org.docx4j.wml.R)93 P (org.docx4j.wml.P)58 Text (org.docx4j.wml.Text)53 PPr (org.docx4j.wml.PPr)23 Jc (org.docx4j.wml.Jc)18 RPr (org.docx4j.wml.RPr)18 Drawing (org.docx4j.wml.Drawing)17 ObjectFactory (org.docx4j.wml.ObjectFactory)17 CTVerticalJc (org.docx4j.wml.CTVerticalJc)16 STVerticalJc (org.docx4j.wml.STVerticalJc)13 FldChar (org.docx4j.wml.FldChar)11 BigInteger (java.math.BigInteger)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tc (org.docx4j.wml.Tc)10 CTBorder (org.docx4j.wml.CTBorder)8 PBdr (org.docx4j.wml.PPrBase.PBdr)8 Ftr (org.docx4j.wml.Ftr)7 File (java.io.File)6 Tr (org.docx4j.wml.Tr)6