Java docx4j粗体文本
我使用docx4j和以下代码对word文档进行搜索和替换:Java docx4j粗体文本,java,ms-word,openxml,wordprocessingml,docx4j,Java,Ms Word,Openxml,Wordprocessingml,Docx4j,我使用docx4j和以下代码对word文档进行搜索和替换: WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(pathFinder.findUploadPath() + filename)); //Get all text elements out of the doc List texts = wordMLPackage.getMainDocumentPa
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(pathFinder.findUploadPath() + filename));
//Get all text elements out of the doc
List texts = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);
// Loop through all "text" elements
for (Object obj : texts) {
Text text = (Text) ((JAXBElement) obj).getValue(); //get the value of the object
// Get the string value
String textValueBefore = text.getValue();
text.setValue(string_afterwards);
}
“string_after”是由一些其他代码行生成的字符串
我的问题是,如何格式化此字符串,使其以粗体样式显示。是否有机会在不更改搜索和替换行的情况下执行此操作?
是否向字符串添加标记?您需要将XPATH\u更改为\u选择\u文本\u节点,以便它选择感兴趣的文本节点的父w:r元素 然后确保w:r有一个w:rPr(runproperties元素),并将其设置为粗体