0
我有这个字符串:Docx4j换行符在字符串
Prueba
Lista:
- li1
- li2
- li3
- li4
Tabulado
Tabulado Tabulado Tabulado Tabulado
Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado
Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado
但是当我准备我的.docx的字符串打印:
Prueba Listas: - li1 - li2 - li3 - li4 Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado
Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado Tabulado
这里是我得到的字符串:
String escDesc = report.getDescription();
if (escDesc.contains("\n")){
//escDesc = escDesc.replaceAll("\\n", System.getProperty("line.separator"));
//escDesc = escDesc.replaceAll("\\n", "<w:br/>");
}
escDesc = StringEscapeUtils.escapeXml(escDesc);
valuesAdd.put("DESCRIPCION", escDesc);
这里是我添加的所有variebles:
private void replacePlaceholders()
throws Exception {
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
VariablePrepare.prepare(wordMLPackage);
documentPart.variableReplace(valuesAdd);
List<SectionWrapper> sectionWrappers = wordMLPackage.getDocumentModel().getSections();
String xml = null;
for (SectionWrapper sw : sectionWrappers) {
HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
if (hfp != null) {
HeaderPart headerPart = hfp.getDefaultHeader();
if (headerPart != null) {
xml = XmlUtils.marshaltoString(headerPart.getJaxbElement());
}
Object obj = null;
try {
obj = XmlUtils.unmarshallFromTemplate(xml, valuesAdd);
} catch (JAXBException e) {
e.printStackTrace();
}
// Inject result into docx
headerPart.setJaxbElement((Hdr) obj);
}
}
}
我想保留\ n,但我不知道我现在必须做什么,我希望有人可以给我一些提示。
这是一个System.out.println(escDesc);
:
而且这是在文档中的字符串: