Search in sources :

Example 51 with Text

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

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

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

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

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

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