UseCasesDTO useCasesDTO = detail(id);
//1.组装数据
Map<String, Object> params = MapUtils.beanToMap(useCasesDTO);
//2.获取目录,创建模板文件
InputStream path = getClass().getResourceAsStream("/templates/usecases/UseCasesTemplate.docx");
String fileName = useCasesDTO.getUseCasesName() + System.currentTimeMillis() + ".docx";
String tmpPath =System.currentTimeMillis() + ".docx";
String pdfPath =System.currentTimeMillis() + ".pdf";
String pdfName = useCasesDTO.getUseCasesName() + System.currentTimeMillis() + ".pdf";
try {
HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
Configure configure = Configure.builder()
// 注册html解析插件
.bind("infoDesc", htmlRenderPolicy)
.bind("basicProcess",htmlRenderPolicy)
.build();
XWPFTemplate template = XWPFTemplate.compile(path, configure).render(params);
FileOutputStream fileOutputStream = new FileOutputStream(tmpPath);
template.writeAndClose(fileOutputStream);
fileOutputStream.close();
catch (Exception e) {
e.printStackTrace();
}
spring boot 根据模版把富文本生成word
最新推荐文章于 2024-05-23 15:26:16 发布