Search in sources :

Example 76 with R

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

the class Docx4j_Helper method setParagraphContent.

/**
 * 设置段落内容
 */
private static void setParagraphContent(P p, RPr rpr, String content) {
    Text t = Docx4j_Helper.factory.createText();
    t.setSpace("preserve");
    t.setValue(content);
    R run = Docx4j_Helper.factory.createR();
    run.setRPr(rpr);
    run.getContent().add(t);
    p.getContent().add(run);
}
Also used : R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 77 with R

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

the class Docx4j_创建批注_S3_Test method createCommentEnd.

public void createCommentEnd(ObjectFactory factory, P p, String pContent, String commentContent, RPr fontRPr, RPr commentRPr, BigInteger commentId, Comments comments) throws Exception {
    Text txt = factory.createText();
    txt.setValue(pContent);
    R run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    p.getContent().add(run);
    Comment commentOne = createComment(factory, commentId, "系统管理员", new Date(), commentContent, commentRPr);
    comments.getComment().add(commentOne);
    p.getContent().add(createRunCommentReference(factory, commentId));
}
Also used : Comment(org.docx4j.wml.Comments.Comment) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text) Date(java.util.Date)

Example 78 with R

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

the class Docx4jStyle_S3 method newImage.

public P newImage(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, byte[] bytes, String filenameHint, String altText, int id1, int id2, long cx) throws Exception {
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, cx, false);
    // Now add the inline in w:p/w:r/w:drawing
    P p = factory.createP();
    R run = factory.createR();
    p.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return p;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 79 with R

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

the class Docx4jStyle_S3 method addCellStyle.

public void addCellStyle(ObjectFactory factory, Tc tableCell, String content, Docx4jStyle_S3 style) {
    if (style != null) {
        P paragraph = factory.createP();
        Text text = factory.createText();
        text.setValue(content);
        R run = factory.createR();
        run.getContent().add(text);
        paragraph.getContent().add(run);
        setHorizontalAlignment(paragraph, style.getHorizAlignment());
        RPr runProperties = factory.createRPr();
        if (style.isBold()) {
            addBoldStyle(runProperties);
        }
        if (style.isItalic()) {
            addItalicStyle(runProperties);
        }
        if (style.isUnderline()) {
            addUnderlineStyle(runProperties);
        }
        setFontSize(runProperties, style.getFontSize());
        setFontColor(runProperties, style.getFontColor());
        setFontFamily(runProperties, style.getCnFontFamily(), style.getEnFontFamily());
        setCellMargins(tableCell, style.getTop(), style.getRight(), style.getBottom(), style.getLeft());
        setCellColor(tableCell, style.getBackground());
        setVerticalAlignment(tableCell, style.getVerticalAlignment());
        setCellBorders(tableCell, style.isBorderTop(), style.isBorderRight(), style.isBorderBottom(), style.isBorderLeft());
        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 80 with R

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

the class Docx4j_工具类_S3_Test method setTcContent.

/**
 * @Description:设置单元格内容,content为null则清除单元格内容
 */
public void setTcContent(Tc tc, RPr rpr, String content) {
    List<Object> pList = tc.getContent();
    P p = null;
    if (pList != null && pList.size() > 0) {
        if (pList.get(0) instanceof P) {
            p = (P) pList.get(0);
        }
    } else {
        p = new P();
        tc.getContent().add(p);
    }
    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(rpr);
        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(rpr);
            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

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