0

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 > を文字列に追加するようなものですか?

4

1 に答える 1

1

XPATH_TO_SELECT_TEXT_NODES を変更して、対象のテキスト ノードの親 w:r 要素を選択する必要があります。

次に、w:r に aw:rPr (run プロパティ要素) があることを確認し、太字に設定します。

于 2012-06-23T21:25:42.800 に答える