1.引入mavna坐标`
<!--操作word类-->
<dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>io.github.draco1023</groupId>
<artifactId>poi-tl-ext</artifactId>
<version>0.3.3</version>
<exclusions>
<exclusion>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
</exclusion>
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
2 .poi-tl-ext插件主要用于富文本内容格式在word展现
3.word模版创建
3.具体代码实现文章来源:https://www.toymoban.com/news/detail-594723.html
/***
*导出快报
*/
public String exportkb(ExportKbVO exportKbVO) {
//获取模板路径文件流
InputStream inputStream = FileUtils.downFileUrl(exportKbVO.getTempleteUrl());
//minio路径
String miniourl = "";
// html渲染插件
HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
Configure configure = Configure.builder()
// 注册html解析插件
.bind("content", htmlRenderPolicy)
.build();
XWPFTemplate template = XWPFTemplate.compile(inputStream,configure).render(new HashMap<String, Object>() {{
//表格上部分
put("fbdw", exportKbVO.getFbdw()); //发布单位
put("kbmc", exportKbVO.getKbMc()); //快报名称
put("qh", exportKbVO.getQh()); //期号
put("fbrq", exportKbVO.getFbrq()); //发布日期
put("bt", exportKbVO.getBt()); //标题
put("reportPersons", exportKbVO.getReportPersons()); // 报送人(多个)
put("reportDeptNames", exportKbVO.getReportDeptNames()); //报送单位(多个)
put("sendDeptNames", exportKbVO.getSendDeptNames()); //发单位(多个)
put("deliverDeptNames", exportKbVO.getDeliverDeptNames()); //送单位(多个)
put("qf", exportKbVO.getQf()); //签发
put("sh", exportKbVO.getSh()); //审核
put("bj", exportKbVO.getBj()); //编校
put("content", exportKbVO.getContent());//内容
}});
String filePath = path + DateUtils.formatDate(new Date(), DateUtils.dateStr) + ".docx";
try {
template.writeAndClose(new FileOutputStream(filePath));
inputStream.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
miniourl = remoteUpload(filePath);
if (StringUtils.isEmpty(miniourl)) {
FileUtils.deleteFile(filePath);
}
return miniourl;
}
4.本文的miniourl路径实质为网络路径的文件。文章来源地址https://www.toymoban.com/news/detail-594723.html
到了这里,关于java 使用POI-TL根据word模版,生成word文件,含图片,富文本。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!