/**
* 写出demo
* @param response
*/
public void docTest() {
String templatePath = "D:\\demo.doc";
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(templatePath);
HWPFDocument doc = new HWPFDocument(in);
Range range = doc.getRange();
// 模板替换
range.replaceText("${title}", "测试报告");
range.replaceText("${date}", new SimpleDateFormat("yyyy-MM-dd")
.format(new Date()));
range.replaceText("${text}", "这是一个demo");
out = new FileOutputStream("D:\\report.doc");
// 输出
doc.write(out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
poi写出doc文档
最新推荐文章于 2024-03-15 17:29:12 发布