Search in sources :

Example 56 with Text

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

the class WordprocessingMLPackageRender method addStyling.

/**
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
 *  到其中. 随后我们将运行块R添加到段落内容中.
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
 */
public void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {
    P paragraph = factory.createP();
    Text text = factory.createText();
    text.setValue(content);
    R run = factory.createR();
    run.getContent().add(text);
    paragraph.getContent().add(run);
    RPr runProperties = factory.createRPr();
    if (bold) {
        addBoldStyle(runProperties);
    }
    if (fontSize != null && !fontSize.isEmpty()) {
        setFontSize(runProperties, fontSize);
    }
    run.setRPr(runProperties);
    tableCell.getContent().add(paragraph);
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) RPr(org.docx4j.wml.RPr) Text(org.docx4j.wml.Text)

Example 57 with Text

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

the class AddingPageNrToFooter method addPageNumberField.

/**
 *  Creating the page number field is nearly the same as creating the field in
 *  the TOC example. The only difference is in the value. We use the PAGE
 *  command, which prints the number of the current page, together with the
 *  MERGEFORMAT switch, which indicates that the current formatting should be
 *  preserved when the field is updated.
 *
 * @param paragraph
 */
private static void addPageNumberField(P paragraph) {
    R run = factory.createR();
    Text txt = new Text();
    txt.setSpace("preserve");
    txt.setValue(" PAGE   \\* MERGEFORMAT ");
    run.getContent().add(factory.createRInstrText(txt));
    paragraph.getContent().add(run);
}
Also used : R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 58 with Text

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

the class Docx4j_工具类_S3_Test method addImageToPara.

/**
 * @Description: 添加图片到段落
 */
public void addImageToPara(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, P paragraph, String filePath, String content, RPr rpr, String altText, int id1, int id2) throws Exception {
    R run = factory.createR();
    if (content != null) {
        Text text = factory.createText();
        text.setValue(content);
        text.setSpace("preserve");
        run.setRPr(rpr);
        run.getContent().add(text);
    }
    InputStream is = new FileInputStream(filePath);
    byte[] bytes = IOUtils.toByteArray(is);
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filePath, altText, id1, id2, false);
    Drawing drawing = factory.createDrawing();
    drawing.getAnchorOrInline().add(inline);
    run.getContent().add(drawing);
    paragraph.getContent().add(run);
}
Also used : Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Text(org.docx4j.wml.Text) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage) FileInputStream(java.io.FileInputStream)

Example 59 with Text

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

the class Docx4j_工具类_S3_Test method appendParaRContent.

/**
 * @Description: 添加段落内容
 */
public void appendParaRContent(P p, RPr runProperties, String content) {
    if (content != null) {
        R run = new R();
        p.getContent().add(run);
        String[] contentArr = content.split("\n");
        Text text = new Text();
        text.setSpace("preserve");
        text.setValue(contentArr[0]);
        run.setRPr(runProperties);
        run.getContent().add(text);
        for (int i = 1, len = contentArr.length; i < len; i++) {
            Br br = new Br();
            // 换行
            run.getContent().add(br);
            text = new Text();
            text.setSpace("preserve");
            text.setValue(contentArr[i]);
            run.setRPr(runProperties);
            run.getContent().add(text);
        }
    }
}
Also used : Br(org.docx4j.wml.Br) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 60 with Text

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

the class Docx4j_替换模板 method setNewTcContent.

/**
 * 设置单元格内容
 *
 * @param tc
 * @param content
 */
public static void setNewTcContent(Tc tc, String content) {
    P p = factory.createP();
    tc.getContent().add(p);
    R run = factory.createR();
    p.getContent().add(run);
    if (content != null) {
        String[] contentArr = content.split("\n");
        Text text = factory.createText();
        text.setSpace("preserve");
        text.setValue(contentArr[0]);
        run.getContent().add(text);
        for (int i = 1, len = contentArr.length; i < len; i++) {
            Br br = factory.createBr();
            // 换行
            run.getContent().add(br);
            text = factory.createText();
            text.setSpace("preserve");
            text.setValue(contentArr[i]);
            run.getContent().add(text);
        }
    }
}
Also used : P(org.docx4j.wml.P) Br(org.docx4j.wml.Br) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

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