Search in sources :

Example 26 with R

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

the class Docx4j_创建批注_S3_Test method createComment.

public Comments.Comment createComment(ObjectFactory factory, BigInteger commentId, String author, Date date, String commentContent, RPr commentRPr) throws Exception {
    Comments.Comment comment = factory.createCommentsComment();
    comment.setId(commentId);
    if (author != null) {
        comment.setAuthor(author);
    }
    if (date != null) {
        comment.setDate(toXMLCalendar(date));
    }
    P commentP = factory.createP();
    comment.getEGBlockLevelElts().add(commentP);
    R commentR = factory.createR();
    commentP.getContent().add(commentR);
    Text commentText = factory.createText();
    commentR.getContent().add(commentText);
    commentR.setRPr(commentRPr);
    commentText.setValue(commentContent);
    return comment;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Comments(org.docx4j.wml.Comments) Comment(org.docx4j.wml.Comments.Comment) Text(org.docx4j.wml.Text)

Example 27 with R

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

the class Docx4j_工具类_S3_Test method setParaRContent.

/**
 * @Description: 设置段落内容
 */
public void setParaRContent(P p, RPr runProperties, String content) {
    R run = null;
    List<Object> rList = p.getContent();
    if (rList != null && rList.size() > 0) {
        for (int i = 0, len = rList.size(); i < len; i++) {
            // 清除内容(所有的r
            p.getContent().remove(0);
        }
    }
    run = new R();
    p.getContent().add(run);
    if (content != null) {
        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 28 with R

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

the class TableWithStyledContent method addStyling.

/**
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
 *  到其中. 随后我们将运行块R添加到段落内容中.
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
 */
private static 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 29 with R

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

the class AddingPageNrToFooter method addFieldEnd.

/**
 * Every fields needs to be delimited by complex field characters. This method
 * adds the delimiter that follows the actual field to the given paragraph.
 * @param paragraph
 */
private static void addFieldEnd(P paragraph) {
    FldChar fldcharend = factory.createFldChar();
    fldcharend.setFldCharType(STFldCharType.END);
    R run3 = factory.createR();
    run3.getContent().add(fldcharend);
    paragraph.getContent().add(run3);
}
Also used : R(org.docx4j.wml.R) FldChar(org.docx4j.wml.FldChar)

Example 30 with R

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

the class AddingTableOfContent method addFieldBegin.

/**
 *  每个域都需要用复杂的域字符来确定界限. 本方法向给定段落添加在真正域之前的界定符.
 *
 *  再一次以创建一个可运行块开始, 然后创建一个域字符来标记域的起始并标记域是'脏的'因为我们想要
 *  在整个文档生成之后进行内容更新.
 *  最后将域字符转换成JAXB元素并将其添加到可运行块, 然后将可运行块添加到段落中.
 *
 *  @param paragraph
 */
private static void addFieldBegin(P paragraph) {
    R run = factory.createR();
    FldChar fldchar = factory.createFldChar();
    fldchar.setFldCharType(STFldCharType.BEGIN);
    fldchar.setDirty(true);
    run.getContent().add(getWrappedFldChar(fldchar));
    paragraph.getContent().add(run);
}
Also used : R(org.docx4j.wml.R) FldChar(org.docx4j.wml.FldChar)

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