请教一个freemaker 转换模板成word 输出时报空指针的问题

demonss1980 2012-09-24 03:18:34
公司最近让做一个报表导出的WORD模板,用freemaker 做的,因为不会,所以先按别人写的,弄了个测试代码如下
Map<String, Object> dataMap = new HashMap<String, Object>();
Configuration configuration = new Configuration();
configuration.setDirectoryForTemplateLoading(new File("resources/"));
configuration.setDefaultEncoding("UTF-8");
dataMap.put("name", "goddy");
dataMap.put("age", "11");
Template t = null;
try {
t = configuration.getTemplate("teste.vm");
} catch (IOException e) {
e.printStackTrace();
}

File outFile = new File("D:/outFile.doc");
Writer out = null;
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
outFile), "UTF-8"));

t.process(dataMap, out);

模板是我用得word2007 生成的一个DOC文件,然后改了扩展名为zip ,把里面的document文件里的内容复制出来的,现在我在运行到t.process(dataMap, out); 时候就报空指针,请问各位大神,这是为什么呢?我尝试换了一下别人写的模板(应该是没有问题的)也是这个情况,只要运行到这里就报空指针了,求指教!
...全文
134 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hengxingbao 2012-09-24
  • 打赏
  • 举报
回复
看看 t 是否为空啊

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧