Search in sources :

Example 71 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 72 with R

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

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

the class Docx4J_简单例子2 method addParagraphTest.

public void addParagraphTest(WordprocessingMLPackage wordMLPackage, MainDocumentPart t, ObjectFactory factory) throws Exception {
    RPr titleRPr = getRPr(factory, "黑体", "000000", "30", STHint.EAST_ASIA, true, false, false, false);
    RPr boldRPr = getRPr(factory, "宋体", "000000", "24", STHint.EAST_ASIA, true, false, false, false);
    RPr fontRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA, false, false, false, false);
    P paragraph = factory.createP();
    setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
    Text txt = factory.createText();
    txt.setValue("七年级上册Unit2 This is just a test. sectionA测试卷答题卡");
    R run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(titleRPr);
    paragraph.getContent().add(run);
    t.addObject(paragraph);
    paragraph = factory.createP();
    setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
    txt = factory.createText();
    txt.setValue("班级:________    姓名:________");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("一、单选题");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(boldRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("1.下列有关仪器用途的说法错误的是(    )");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("A.烧杯用于较多量试剂的反应容器");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("B.烧杯用于较多量试剂的反应容器");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("C.烧杯用于较多量试剂的反应容器");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("D.烧杯用于较多量试剂的反应容器");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "0", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    txt = factory.createText();
    txt.setValue("2.下列实验操作中,正确的是(    ) ");
    run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    paragraph.getContent().add(run);
    // 段前8磅 段后0.5磅
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "160", "10");
    t.addObject(paragraph);
    paragraph = factory.createP();
    File file = new File("f:/saveFile/temp/image1.png");
    java.io.InputStream is = new java.io.FileInputStream(file);
    createImageParagraph(wordMLPackage, factory, paragraph, "img_1", "A.", BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
    file = new File("f:/saveFile/temp/image2.png");
    is = new java.io.FileInputStream(file);
    createImageParagraph(wordMLPackage, factory, paragraph, "img_2", StringUtils.leftPad("B.", 20), BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "1", "3");
    t.addObject(paragraph);
    paragraph = factory.createP();
    file = new File("f:/saveFile/temp/image3.png");
    is = new java.io.FileInputStream(file);
    createImageParagraph(wordMLPackage, factory, paragraph, "img_3", "C.", BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
    file = new File("f:/saveFile/temp/image4.png");
    is = new java.io.FileInputStream(file);
    createImageParagraph(wordMLPackage, factory, paragraph, "img_4", StringUtils.leftPad("D.", 20), BufferUtil.getBytesFromInputStream(is), JcEnumeration.LEFT);
    setParagraphSpacing(factory, paragraph, JcEnumeration.LEFT, "1", "3");
    t.addObject(paragraph);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) RPr(org.docx4j.wml.RPr) Text(org.docx4j.wml.Text) File(java.io.File)

Example 74 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, 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);
    ftr.getContent().add(footerP);
    return ftr;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) Ftr(org.docx4j.wml.Ftr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Text(org.docx4j.wml.Text)

Example 75 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, 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("3"));
    pBdr.setBetween(value);
    pPr.setPBdr(pBdr);
    p.setPPr(pPr);
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");
    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