1

我有一个 odt 模板文件,目前看起来像这样:

 ${heading}


 ${documentDate}

                        1. ${orderedList}

使用 hashmap 填充标题和 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

我希望它自动处理枚举。这可能吗?我用谷歌搜索并查看了示例,但找不到答案..

4

0 回答 0