本文整理汇总了Java中org.docx4j.wml.Text.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Text.setValue方法的具体用法?Java Text.setValue怎么用?Java Text.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.wml.Text
的用法示例。
在下文中一共展示了Text.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addStyling
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* 这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;
* 第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
* 到其中. 随后我们将运行块R添加到段落内容中.
* 直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
* 这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
*/
public 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);
}
示例2: setNewTcContent
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* 设置单元格内容
*
* @param tc
* @param content
*/
public static void setNewTcContent(Tc tc, String content) {
P p = factory.createP();
tc.getContent().add(p);
R run = factory.createR();
p.getContent().add(run);
if (content != null) {
String[] contentArr = content.split("\n");
Text text = factory.createText();
text.setSpace("preserve");
text.setValue(contentArr[0]);
run.getContent().add(text);
for (int i = 1, len = contentArr.length; i < len; i++) {
Br br = factory.createBr();
run.getContent().add(br);// 换行
text = factory.createText();
text.setSpace("preserve");
text.setValue(contentArr[i]);
run.getContent().add(text);
}
}
}
示例3: createComment
import org.docx4j.wml.Text; //导入方法依赖的package包/类
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;
}
示例4: createRun
import org.docx4j.wml.Text; //导入方法依赖的package包/类
private R createRun(final String styleId, final String text) {
final R r = this.wmlObjectFactory.createR();
final RPr rpr = this.wmlObjectFactory.createRPr();
r.setRPr(rpr);
if (styleId != null) {
final RStyle rstyle = this.wmlObjectFactory.createRStyle();
rstyle.setVal(styleId);
rpr.setRStyle(rstyle);
}
final Text textElement = this.wmlObjectFactory.createText();
textElement.setValue(text);
final JAXBElement<Text> wrappedText = this.wmlObjectFactory.createRT(textElement);
r.getContent().add(wrappedText);
return r;
}
示例5: addHeaderParagraphOfText
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
*
* @param mainDocumentPart
* @param workItemID
* @param simpleText
* @param styleId
* @return
*/
private static P addHeaderParagraphOfText(MainDocumentPart mainDocumentPart, Integer workItemID, String simpleText, String styleId) {
ObjectFactory factory = Context.getWmlObjectFactory();
P p = factory.createP();
if (simpleText!=null) {
Text t = factory.createText();
t.setValue(simpleText);
R run = factory.createR();
run.getContent().add(t);
p.getContent().add(run);
BookmarkAdd.bookmarkRun(p, run, ITEM_BOOKMARK_PREFIX+workItemID, workItemID);
}
if (mainDocumentPart.getPropertyResolver().activateStyle(styleId)) {
// Style is available
org.docx4j.wml.PPr pPr = factory.createPPr();
p.setPPr(pPr);
org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
pPr.setPStyle(pStyle);
pStyle.setVal(styleId);
} else {
LOGGER.debug("StyleID " + styleId + " not available");
}
return p;
}
示例6: handleMatchedText
import org.docx4j.wml.Text; //导入方法依赖的package包/类
protected void handleMatchedText() {
resultingTexts.add(startText);
startText.setValue(mergedTextsString.toString());
for (Text mergedText : mergedTexts) {
if (mergedText != startText) {
mergedText.setValue("");
textsToRemove.add(mergedText);
}
}
if (!containsStartOfRegexp(startText.getValue().replaceAll(regexp, ""))) {
startText = null;
mergedTexts = null;
mergedTextsString = null;
} else {
mergedTexts = new HashSet<Text>();
mergedTexts.add(startText);
mergedTextsString = new StringBuilder(startText.getValue());
}
}
示例7: findNameForCurrentTable
import org.docx4j.wml.Text; //导入方法依赖的package包/类
protected void findNameForCurrentTable(final TableManager currentTable) {
new TraversalUtil(currentTable.firstRow,
new RegexpFinder<P>(docxFormatter, AbstractFormatter.BAND_NAME_DECLARATION_PATTERN, P.class) {
@Override
protected void onFind(P paragraph, Matcher matcher) {
if (currentTable.bandName == null) {
super.onFind(paragraph, matcher);
currentTable.bandName = matcher.group(1);
String bandNameDeclaration = matcher.group();
Set<Text> mergedTexts = new TextMerger(paragraph, bandNameDeclaration).mergeMatchedTexts();
for (Text text : mergedTexts) {
text.setValue(text.getValue().replace(bandNameDeclaration, ""));
}
}
}
});
}
示例8: inlineToDocx
import org.docx4j.wml.Text; //导入方法依赖的package包/类
@Override
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) {
try {
Image image = new Image(paramValue, paramsMatcher);
if (image.isValid()) {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, resolveTextPartForDOCX(text, wordPackage),
image.imageContent);
Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, false);
ImageSize oldSize = imagePart.getImageInfo().getSize();
double widthExtent = (double) image.width / oldSize.getWidthPx();
double heightExtent = (double) image.height / oldSize.getHeightPx();
inline.getExtent().setCx((long) (inline.getExtent().getCx() * widthExtent));
inline.getExtent().setCy((long) (inline.getExtent().getCy() * heightExtent));
org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing();
R run = (R) text.getParent();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
text.setValue("");
}
} catch (Exception e) {
throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e);
}
}
示例9: addPageNumberField
import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void addPageNumberField(ObjectFactory factory, P paragraph) {
R run = factory.createR();
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue("PAGE \\* MERGEFORMAT ");
run.getContent().add(factory.createRInstrText(txt));
paragraph.getContent().add(run);
}
示例10: addRowToTable
import org.docx4j.wml.Text; //导入方法依赖的package包/类
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);
}
示例11: createFooter
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* First we create a footer, a paragraph, a run and a text. We add the given
* given content to the text and add that to the run. The run is then added to
* the paragraph, which is in turn added to the footer. Finally we return the
* footer.
* @param content
* @return
*/
public static Ftr createFooter(String content) {
Ftr footer = factory.createFtr();
P paragraph = factory.createP();
R run = factory.createR();
Text text = new Text();
text.setValue(content);
run.getContent().add(text);
paragraph.getContent().add(run);
footer.getContent().add(paragraph);
return footer;
}
示例12: addImageToPara
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* @Description: 添加图片到段落
*/
public void addImageToPara(WordprocessingMLPackage wordMLPackage,
ObjectFactory factory, P paragraph, String filePath,
String content, RPr rpr, String altText, int id1, int id2)
throws Exception {
R run = factory.createR();
if (content != null) {
Text text = factory.createText();
text.setValue(content);
text.setSpace("preserve");
run.setRPr(rpr);
run.getContent().add(text);
}
InputStream is = new FileInputStream(filePath);
byte[] bytes = IOUtils.toByteArray(is);
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
.createImagePart(wordMLPackage, bytes);
Inline inline = imagePart.createImageInline(filePath, altText, id1,
id2, false);
Drawing drawing = factory.createDrawing();
drawing.getAnchorOrInline().add(inline);
run.getContent().add(drawing);
paragraph.getContent().add(run);
}
示例13: setParagraphContent
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* 设置段落内容
*/
private 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);
}
示例14: replaceTcContent
import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
* 替换单元格内容
*/
private void replaceTcContent(Tc tc, String value) {
List<Object> rtnList = getAllElementFromObject(tc, Text.class);
if (rtnList == null || rtnList.size() == 0) {
return;
}
Text textElement = (Text) rtnList.get(0);
textElement.setValue(value);
}
示例15: addCellStyle
import org.docx4j.wml.Text; //导入方法依赖的package包/类
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);
}
}