ODT 文档中带有 jOpenDocument 的字段中的新行

New line in field with jOpenDocument in ODT document

我正在尝试使用 jOpenDocument 库填写来自 java 的模板。

我想在字段中另起一行。 正常的换行符 (\n) 不起作用。

当我在文档中手动执行此操作并查看 xml 文件 (content.xml) 时,我明白了为什么这不起作用。对于字段中的每一行,都有一个单独的段落。

所以也许有一种方法可以将多个段落合并到一个对象中,然后使用多个段落对象调用 setField()。但直到现在我还没有找到任何解决方案。

代码示例:

EngineTemplate template = new RhinoTemplate(templateFile);
template.setField("nameField", "this is the content\nI wish to be multilined"); 

基本上默认情况下会跳过 \n,但您可以通过在模板中以 %enc: 开头的字段名称来更改它。

以下是 org.jopendocument.dom.template.engine.Processor class 文档中的解释:

Generates the final document content from the preprocessed template content. The behaviour of the substitution of fields can be controlled with prefixes:

AS_STR the following expression will be substitued as a String. For an XML element its tree will be outputed.

ENCODE the following expression will be converted to a String with toString() and then encoded using org.jopendocument.dom.OOXML.encodeWS(java.lang.String).

OO_XML the following expression will be converted to a String with toString() and then parsed as OO XML.

If none of these is specified, an XML element will be treated as OO XML to be grafted (only its children), else the value will simply be set as text of the field.

并且 ENCODE 字段声明为:

public static final String ENCODE = "%enc:";