WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(templatePath));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
HashMap<String, String> mappings = new HashMap<String, String>();
mappings.put("years", "2021");
mappings.put("month", "9月\n8月");
mappings.put("day", "3");
documentPart.variableReplace(mappings);
如上代码,在执行时 ,9月和8月间并不会换行,而是输出\n ;
输出如下:
9月\n8月
解决方案:
String skip = "</w:t> " +
" </w:r> " +
" </w:p> " +
" <w:p/> " +
" <w:p> " +
" <w:pPr>