private static void createWord() {
//
try {
String templatePath = "E:\\upload_file\\me.doc";
HWPFDocument hwpfDocument = new HWPFDocument(new FileInputStream(new File(templatePath)));
Range range = hwpfDocument.getRange();
range.replaceText("${title}", "标题");
range.replaceText("${reportDate}", "2019-04-28");
range.replaceText("${reportContent}", "报告内容");
range.replaceText("${content1}", "内容1");
range.replaceText("${content2}", "内容2");
range.replaceText("${content3}", "内容3");
range.replaceText("${reportPerson}", "me");
OutputStream os = new FileOutputStream(new File("me1.doc"));
hwpfDocument.write(os);
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
java生成word
最新推荐文章于 2024-04-30 20:34:13 发布