栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java实现导出word

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java实现导出word

1,需要引用的maven仓库地址


   commons-io
   commons-io


   com.deepoove
   poi-tl

如果要导出的内容包含富文本,则需要引用以下资源,来解析富文本标签


   org.jsoup
   jsoup
   1.11.3

2,创建word模板,参考地址:Poi-tl documentation

3,后台实现

		Map map= new HashMap<>();
        map.put("t1","trst");
        String ss = 

测试

//处理带富文本的内容 map.put("t2",Jsoup.parse(ss).body().text()); List files = new ArrayList<>(); String writePath = "d:/word/test" + File.separator; File writeFile = new File(writePath); if (!writeFile.exists()) {// 判断目录是否存在 writeFile.mkdirs(); } XWPFTemplate template = XWPFTemplate.compile(resource.getInputStream()).render(map); response.setContentType("application/octet-stream"); response.setHeader("Content-disposition","attachment;filename=""+"详情.docx"); OutputStream out = response.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(out); template.write(bos); bos.flush(); out.flush(); PoitlIOUtils.closeQuietlyMulti(template, bos, out);

map中的key值和模板中的变量需要一一对应

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/759680.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号