当前位置: 首页 > news >正文

争对银行排队做一网站湘潭营销型网站建设

争对银行排队做一网站,湘潭营销型网站建设,做名片哪个网站可以找,自己做网站要不要租服务器使用 poi-tl 根据模板生成 word 文件。 使用 xdocreport 将 docx 文件转换为 pdf 文件。 xdocreport 也支持根据模板导出 word ,但是 poi-tl 的功能更齐全,操作更简单,文档清晰。 poi-tl 、xdocreport 内部均依赖了 poi ,要注意两…

使用 poi-tl 根据模板生成 word 文件。
使用 xdocreport 将 docx 文件转换为 pdf 文件。

xdocreport 也支持根据模板导出 word ,但是 poi-tl 的功能更齐全,操作更简单,文档清晰。
poi-tl 、xdocreport 内部均依赖了 poi ,要注意两者中 poi 和 自身项目引用的 poi 的版本是否存在冲突。

文章目录

    • Pom 依赖
    • 生成 DOCX 文件
      • 创建 DOCX 模板
      • 生成 DOCX 文档
        • 创建模板填充类
        • 生成文件(多种方式)
        • 生成效果
      • DOCX 转 PDF
        • PDF 生成效果
        • 注意

Pom 依赖

使用 poi 5.2.2 ,poi-tl 1.12.1 ,xdocreport 2.0.3

<!--        poi依赖--><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.2</version></dependency>
<!--        poi-tl依赖--><dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.12.1</version></dependency>
<!--        xdocreport依赖--><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-full</artifactId><version>5.2.2</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>xdocreport</artifactId><version>2.0.3</version></dependency><dependency><groupId>fr.opensagres.xdocreport</groupId><artifactId>org.apache.poi.xwpf.converter.pdf</artifactId><version>1.0.6</version></dependency>

生成 DOCX 文件

创建 DOCX 模板

根据官方文档按要求创建模板,并放在resources文件夹下。官方文档 http://deepoove.com/poi-tl/。
在这里插入图片描述
在这里插入图片描述

生成 DOCX 文档

创建模板填充类

其实也可以在生成文件时使用 Map 类型的方式填充文件内容,如下

XWPFTemplate.compile(inputStream).render(new HashMap<String, Object>(){{put("title", "Hi, poi-tl Word模板引擎");
}});

但是使用实体类更规范一些。

@Data
public class ChildRoundsProvalDocxEntity {private String childName;//孩子姓名private String identify;//身份证号private String gender;//性别private String childRounds;//孩次private PictureRenderData avatar;//头像地址private String entryDate;//入院时间private String gardenMonths;//孩次private String charge;//每月收费private String fatherName;//父亲姓名private String fatherIdentify;//父亲身份证号private String motherName;//母亲姓名private String motherIdentify;//母亲身份证号private String address;//住址及联系方式private String firstChildName;//第一个子女姓名private String firstChildIdentify;//第一个子女身份证号private String secondChildName;//第二个子女姓名private String secondChildIdentify;//第二个子女身份证号private String signDate;//签署日期
}

生成文件(多种方式)

1、生成一个文件输入流,方便用于再次编辑
不要在方法内部将输入流关闭

/*** 生成文件到输入流中* @param templatePath* @param data* @return*/
public InputStream createWordFile1(Object data){Resource templateFile = resourceLoader.getResource("classpath:wordtemplate/childRoundsProval.docx");XWPFTemplate template = null;InputStream resultStream = null;try {// word模板填充InputStream inputStream = templateFile.getInputStream();template = XWPFTemplate.compile(inputStream).render(data);resultStream = PoitlIOUtils.templateToInputStream(template);PoitlIOUtils.closeQuietlyMulti(template);} catch (Exception e) {log.error("导出失败,异常原因:" + e.getMessage());} finally {try {if (template != null) {template.close();}} catch (Exception e) {log.error("流关闭失败,异常原因:" + e.getMessage());}}return resultStream;
}

2、生成docx到输出流中,一般是在网络响应中直接输出,浏览器去下载

public void createWordFile2(Object data, HttpServletResponse httpServletResponse){//获取模板信息Resource templateFile = resourceLoader.getResource("classpath:wordtemplate/childRoundsProval.docx");XWPFTemplate template = null;docName = URLEncoder.encode(docName, StandardCharsets.UTF_8);try {httpServletResponse.setContentType("application/octet-stream");httpServletResponse.addHeader("Content-Disposition", "attachment;filename=" + docName + ".docx");httpServletResponse.addHeader("filename", docName);// word模板内容填充InputStream inputStream = templateFile.getInputStream();template = XWPFTemplate.compile(inputStream).render(data);OutputStream out = httpServletResponse.getOutputStream();//要记得关闭BufferedOutputStream bos = new BufferedOutputStream(out);//要记得关闭template.write(bos);bos.flush();out.flush();PoitlIOUtils.closeQuietlyMulti(template, bos, out);} catch (Exception e) {log.error("导出失败,异常原因:" + e.getMessage());throw new BaseException("Word文档生成失败");} finally {try {if (template != null) {template.close();}} catch (Exception e) {log.error("流关闭失败,异常原因:" + e.getMessage());}}
}

3、直接生成文件到指定路径

public void createWordFile3(Object data, String path){//获取模板信息Resource templateFile = resourceLoader.getResource("classpath:wordtemplate/childRoundsProval.docx");XWPFTemplate template = null;try {// word模板内容填充InputStream inputStream = templateFile.getInputStream();template = XWPFTemplate.compile(inputStream).render(data);template.writeToFile(path);//文件夹路径必须存在 可以提前创建PoitlIOUtils.closeQuietlyMulti(template);} catch (Exception e) {log.error("导出失败,异常原因:" + e.getMessage());throw new BaseException("Word文档生成失败");} finally {try {if (template != null) {template.close();}} catch (Exception e) {log.error("流关闭失败,异常原因:" + e.getMessage());}}
}

生成效果

在这里插入图片描述

DOCX 转 PDF

初始化 XWPFDocument 需要一个输入流,以下是直接使用文件输入流去初始化。

FileInputStream inputStream1 = new FileInputStream("docx文件位置.docx");
XWPFDocument xwpfDocument = new XWPFDocument(inputStream1);
PdfOptions options = PdfOptions.create();
try (OutputStream outPDF = Files.newOutputStream(Paths.get("要生成的pdf位置.pdf"))) {PdfConverter.getInstance().convert(xwpfDocument.getXWPFDocument(), outPDF, options);
} catch (IOException e) {log.error("PDF转换失败",e);
}

PDF 生成效果

在这里插入图片描述

注意

DOCX 模板中如果表格元素中放了图片(如上图中的头像),要确保生成的文件中的图片大小不超过模板中单元格大小。
即图片所在单元格不能被图片撑大,否则图片在转换成PDF时无法展示。


文章转载自:
http://faveolate.ddfp.cn
http://celioscope.ddfp.cn
http://psychrometer.ddfp.cn
http://flatwork.ddfp.cn
http://churchless.ddfp.cn
http://constringency.ddfp.cn
http://rubus.ddfp.cn
http://hypochlorhydria.ddfp.cn
http://epicene.ddfp.cn
http://fleeceable.ddfp.cn
http://standee.ddfp.cn
http://miliary.ddfp.cn
http://disown.ddfp.cn
http://lust.ddfp.cn
http://thoracicolumbar.ddfp.cn
http://unaptly.ddfp.cn
http://backstay.ddfp.cn
http://roemer.ddfp.cn
http://swoosh.ddfp.cn
http://siderosis.ddfp.cn
http://catafalque.ddfp.cn
http://defer.ddfp.cn
http://wormlike.ddfp.cn
http://clarinet.ddfp.cn
http://phytocidal.ddfp.cn
http://intercostal.ddfp.cn
http://curch.ddfp.cn
http://raguly.ddfp.cn
http://underproductive.ddfp.cn
http://murine.ddfp.cn
http://geometrician.ddfp.cn
http://swati.ddfp.cn
http://decode.ddfp.cn
http://bubu.ddfp.cn
http://scaffold.ddfp.cn
http://antitoxin.ddfp.cn
http://nocuously.ddfp.cn
http://semasiology.ddfp.cn
http://diluvium.ddfp.cn
http://wiretap.ddfp.cn
http://olim.ddfp.cn
http://circassia.ddfp.cn
http://eudiometric.ddfp.cn
http://rainmaker.ddfp.cn
http://monkshood.ddfp.cn
http://beograd.ddfp.cn
http://parquet.ddfp.cn
http://income.ddfp.cn
http://colicroot.ddfp.cn
http://haematocyte.ddfp.cn
http://flagellated.ddfp.cn
http://hygrograph.ddfp.cn
http://blazonment.ddfp.cn
http://keratosulphate.ddfp.cn
http://fundi.ddfp.cn
http://noticeably.ddfp.cn
http://contra.ddfp.cn
http://extemportize.ddfp.cn
http://fractocumulus.ddfp.cn
http://blah.ddfp.cn
http://macrochemistry.ddfp.cn
http://traditionalistic.ddfp.cn
http://falcongentle.ddfp.cn
http://hyperuricemia.ddfp.cn
http://belay.ddfp.cn
http://overdaring.ddfp.cn
http://miolithic.ddfp.cn
http://jimmy.ddfp.cn
http://toothcomb.ddfp.cn
http://patrist.ddfp.cn
http://gemel.ddfp.cn
http://mycelial.ddfp.cn
http://evan.ddfp.cn
http://lemniscus.ddfp.cn
http://mondial.ddfp.cn
http://enhalo.ddfp.cn
http://rapper.ddfp.cn
http://crossruff.ddfp.cn
http://searcher.ddfp.cn
http://unsheltered.ddfp.cn
http://vibratiuncle.ddfp.cn
http://nhp.ddfp.cn
http://epact.ddfp.cn
http://hydrotactic.ddfp.cn
http://etorofu.ddfp.cn
http://catecholaminergic.ddfp.cn
http://jedda.ddfp.cn
http://agency.ddfp.cn
http://noninitially.ddfp.cn
http://mmpi.ddfp.cn
http://stingray.ddfp.cn
http://cheskey.ddfp.cn
http://synthase.ddfp.cn
http://prepend.ddfp.cn
http://anticlimax.ddfp.cn
http://catapult.ddfp.cn
http://vasculitis.ddfp.cn
http://validating.ddfp.cn
http://industrious.ddfp.cn
http://gamesmanship.ddfp.cn
http://www.hrbkazy.com/news/85474.html

相关文章:

  • 中牟网站建设云搜索系统
  • 网站怎么添加横幅网页设计首页制作
  • 做羞羞的事情的网站个人如何做网络推广
  • 广州知名网站建设哪家好线上推广策划方案范文
  • 网站源码破解版网络运营培训班多少钱
  • 淘宝客网站怎么备案汕头seo按天付费
  • 北京网站备案查询厦门seo哪家强
  • 利用网站制作网页百度百科词条创建入口
  • 网页设计与制作教程第六版课后答案seo服务内容
  • 网站地图制作软件太原seo团队
  • 网站修改联系方式石家庄最新疫情
  • 日本人爱做月光影院网站自媒体seo优化
  • 建站系统低价建站新闻资讯以服务营销出名的企业
  • 什么网站做免单衣服网络推广培训去哪里好
  • 开发公司与物业公司合同如何优化关键词排名快速首页
  • 珠海外贸网站建设网站制作公司有哪些
  • 手机网站建设策划书重庆seo代理
  • 职业生涯规划大赛策划书方案安卓优化大师app下载安装
  • 网站备案接入服务商微信怎么引流营销呢
  • 滕州做网站互联网营销策划是做什么的
  • java个人兼职网站开发百度开户多少钱
  • 什么是网页站点网店运营在哪里学比较好些
  • 做企业网站建设挣钱吗免费网站统计
  • 一台ip做两个网站百度首页排名优化多少钱
  • 技术支持 昆明网站建设考研培训班集训营
  • wordpress如何修改自己的网页seo广告
  • 如何做个网站销售成功案例分享
  • 商品网站源码作品推广
  • 深圳市工程建设造价网站专业做网站建设的公司
  • 长春火车站是北站吗软文推广多少钱