Search in sources :

Example 46 with Text

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

the class Docx4J_简单例子2 method createImageParagraph.

// 段落中插入文字和图片
public P createImageParagraph(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P p, String fileName, String content, byte[] bytes, JcEnumeration jcEnumeration) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(fileName, "这是图片", 1, 2, false);
    Text text = factory.createText();
    text.setValue(content);
    text.setSpace("preserve");
    R run = factory.createR();
    p.getContent().add(run);
    run.getContent().add(text);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    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);
    p.setPPr(pPr);
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");
    return p;
}
Also used : Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) STVerticalJc(org.docx4j.wml.STVerticalJc) Jc(org.docx4j.wml.Jc) CTVerticalJc(org.docx4j.wml.CTVerticalJc) Text(org.docx4j.wml.Text) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 47 with Text

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

the class Docx4J_简单例子2 method getTextHdr.

public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage, ObjectFactory factory, Part sourcePart, String content, JcEnumeration jcEnumeration) throws Exception {
    Hdr hdr = factory.createHdr();
    P headP = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    headP.getContent().add(run);
    PPr pPr = headP.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);
    headP.setPPr(pPr);
    setParagraphSpacing(factory, headP, jcEnumeration, "0", "0");
    hdr.getContent().add(headP);
    hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration));
    return hdr;
}
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) Hdr(org.docx4j.wml.Hdr) 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 48 with Text

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

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

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

Aggregations

Text (org.docx4j.wml.Text)62 R (org.docx4j.wml.R)53 P (org.docx4j.wml.P)32 PPr (org.docx4j.wml.PPr)14 RPr (org.docx4j.wml.RPr)12 Jc (org.docx4j.wml.Jc)10 CTVerticalJc (org.docx4j.wml.CTVerticalJc)9 File (java.io.File)8 Tc (org.docx4j.wml.Tc)7 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)6 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)6 STVerticalJc (org.docx4j.wml.STVerticalJc)6 BigInteger (java.math.BigInteger)5 Br (org.docx4j.wml.Br)5 ObjectFactory (org.docx4j.wml.ObjectFactory)5 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)4 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)4 CTShd (org.docx4j.wml.CTShd)4 Ftr (org.docx4j.wml.Ftr)4 Tbl (org.docx4j.wml.Tbl)4