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;
}
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);
}
}
}
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);
}
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);
}
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);
}
Aggregations