我有一个odt模板文件,目前看起来像这样:
${heading}
${documentDate}
1. ${orderedList}
使用散列图填充标题和documentDate非常简单。我的javacode看起来像这样:
public class CreateODF {
public boolean createODF() {
try {
DocumentTemplateFactory documentTemplateFactory = new DocumentTemplateFactory();
DocumentTemplate template = documentTemplateFactory.getTemplate(new File("/tmp/template.odt"));
Map<String, Object> dataModel = createDataModel();
template.createDocument(dataModel, new FileOutputStream("/tmp/result.odt"));
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static Map<String, Object> createDataModel() {
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("heading", "Some heading");
dataModel.put("documentDate", "03.03.2015");
dataModel.put("orderedList", "Element one\nElement two\nElement three");
return dataModel;
}
}
结果如下:
Some heading
03.03.2015
1. Element one
Element two
Element three
我希望它能自动处理枚举。这可能吗?我用Google搜索并查看了示例,但无法找到答案..