docx4j と次のコードを使用して、Word 文書の検索と置換を行います。
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_afterwards」は、他のコード行によって生成された文字列です。
私の問題は、この文字列をフォーマットして、太字で表示することです。
検索と置換の行を変更せずにそれを行う機会はありますか?
タグ < b > を文字列に追加するようなものですか?