use of org.docx4j.wml.Text 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.Text 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.Text 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.Text in project docx4j-template by vindell.
the class AddingTableOfContent method addTableOfContentField.
/**
* (不知道该怎么翻译, 因此将英文原注释保留)
* Adds the field that Word uses to create a table of content to the paragraph.
*
* First we create a run and a text. Then we indicate that all spaces in the
* text are to be preserved and set the value to that of the TOC field.
* This field definition takes some arguments. The exact definition can be
* found in §17.16.5.58 of the Office Open XML standard. In this case we
* specify that we want to include all paragrapsh formatted with headings of
* levels 1-3 (\0 “1-3”). We also specify that we want all entries to be
* hyperlinks (\h), that we want to hide tab leader and page numbers in Web
* layout view (\z), and that we want to use the applied paragraph outline
* level (\\u).
* Finally we take the text and use it to create a JAXB element containing text
* and add this to the run, which we then add to the given paragraph.
*
* 将Word用于创建目录表的域添加到段落中.
*
* 首先创建一个可运行块和一个文本. 然后指出文本中所有的空格都被保护并给TOC域设置值. 这个域定义
* 需要一些参数, 确切定义可以在Office Open XML标准的§17.16.5.58找到, 这种情况我们指定所有
* 段落使用1-3级别的标题来格式化(\0 "1-3"). 我们同时指定所有的实体作为超链接(\h), 而且在Web
* 视图中隐藏标签和页码(\z), 我们要使用段落大纲级别应用(\\u).
* 最后使用文本对象创建了一个JAXB元素包含文本并添加到随后被添加到段落中的可运行块中.
*
* @param paragraph
*/
private static void addTableOfContentField(P paragraph) {
R run = factory.createR();
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue("TOC \\o \"1-3\" \\h \\z \\u");
run.getContent().add(factory.createRInstrText(txt));
paragraph.getContent().add(run);
}
use of org.docx4j.wml.Text in project docx4j-template by vindell.
the class WMLPackageUtils method addRowToTable.
public static void addRowToTable(Tbl reviewtable, Tr templateRow, Map<String, String> replacements) {
Tr workingRow = (Tr) XmlUtils.deepCopy(templateRow);
List<?> textElements = getTargetElements(workingRow, Text.class);
for (Object object : textElements) {
Text text = (Text) object;
String replacementValue = (String) replacements.get(text.getValue());
if (replacementValue != null)
text.setValue(replacementValue);
}
reviewtable.getContent().add(workingRow);
}
Aggregations