Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java docx4j粗体文本_Java_Ms Word_Openxml_Wordprocessingml_Docx4j - Fatal编程技术网

Java docx4j粗体文本

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

我使用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_after”是由一些其他代码行生成的字符串

我的问题是,如何格式化此字符串,使其以粗体样式显示。
是否有机会在不更改搜索和替换行的情况下执行此操作?

是否向字符串添加标记?

您需要将XPATH\u更改为\u选择\u文本\u节点,以便它选择感兴趣的文本节点的父w:r元素

然后确保w:r有一个w:rPr(runproperties元素),并将其设置为粗体