第一步:准备模板文件
第二步:pom导入jar;
第三步:编写测试代码;
第四步:查看效果;
最后:最重要部分,代码共享
public void ExportWord(String adcd) throws Exception {
String tmpFile = JeeThinkConfig.getRegionpath()+"/temp/template.docx";
String expFile = JeeThinkConfig.getRegionpath()+"/temp/result.docx";
String exppdfFile = JeeThinkConfig.getRegionpath()+"/temp/result.pdf";
// build(new File(tmpFile), datas, expFile);
Map<String, Object> datas1 = new HashMap<String, Object>() {
{
//本地图片
put("localPicture", new PictureRenderData(550, 400, JeeThinkConfig.getRegionpath()+"png/00G_202103290824024.png"));
put("title", "标题部份");
put("content", "这里是内容,测试使用导出到Word的内容!");
}
};
XWPFTemplate template = XWPFTemplate.compile(tmpFile)
.render(datas1);
FileOutputStream out = new FileOutputStream(expFile);
template.write(out);
out.flush();
out.close();
template.close();
XWPFDocument document;
InputStream doc = new FileInputStream(expFile);
document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out1 = new FileOutputStream(exppdfFile);
PdfConverter.getInstance().convert(document, out1, options);
doc.close();
out.close();
}
感谢支持技术分享,请扫码点赞支持:
技术合作交流qq:2401315930