Search in sources :

Example 81 with P

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

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

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

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

Example 85 with P

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

the class Docx4j_Helper method name.

public static void name() throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    String titleStr = "测试插入段落";
    P p = Docx4j_Helper.factory.createP();
    String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
    RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
    setParagraphContent(p, rpr, titleStr);
    documentPart.getContent().add(5, p);
    String tblPrStr = "<w:tblPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:tblW w:w=\"8522\" w:type=\"dxa\"/><w:tblBorders><w:top w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:left w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:insideH w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/></w:tblBorders></w:tblPr>";
    Tbl tbl = Docx4j_Helper.factory.createTbl();
    TblPr tblPr = (TblPr) XmlUtils.unmarshalString(tblPrStr);
    tbl.setTblPr(tblPr);
    Tr tr = Docx4j_Helper.factory.createTr();
    Tc tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tbl.getContent().add(tr);
    tr = Docx4j_Helper.factory.createTr();
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tc = Docx4j_Helper.factory.createTc();
    tr.getContent().add(tc);
    tbl.getContent().add(tr);
    documentPart.getContent().add(9, tbl);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
Also used : P(org.docx4j.wml.P) RPr(org.docx4j.wml.RPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) TblPr(org.docx4j.wml.TblPr) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) Tc(org.docx4j.wml.Tc)

Aggregations

P (org.docx4j.wml.P)101 R (org.docx4j.wml.R)58 Text (org.docx4j.wml.Text)32 Test (org.junit.Test)23 PPr (org.docx4j.wml.PPr)22 RPr (org.docx4j.wml.RPr)21 ObjectFactory (org.docx4j.wml.ObjectFactory)18 Jc (org.docx4j.wml.Jc)16 BigInteger (java.math.BigInteger)14 CTVerticalJc (org.docx4j.wml.CTVerticalJc)14 Drawing (org.docx4j.wml.Drawing)14 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)13 STVerticalJc (org.docx4j.wml.STVerticalJc)11 Tc (org.docx4j.wml.Tc)11 File (java.io.File)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tbl (org.docx4j.wml.Tbl)10 Tr (org.docx4j.wml.Tr)10 Br (org.docx4j.wml.Br)9