当前位置: 首页 > 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://www.mnyf.cn/news/37575.html

相关文章:

  • 安徽定制型网站建设推广郑州抖音seo
  • 网站开发用不用写交互网站seo优化包括哪些方面
  • 佛山网站建设在哪广州seo外包多少钱
  • asp.net 跳转别的网站百度推广开户联系方式
  • 做考勤的网站大一html网页制作作业简单
  • 山西网站建设企业seo手机关键词网址
  • 建设网站优化网盘手机app官网下载
  • 做模具的都有什么网站整合营销方案案例
  • 系统花钱做任务的小说魅网站小学生简短小新闻十条
  • 礼品行业网站建设短视频培训
  • 做网站怎么拿框架的原代码珠海seo关键词排名
  • 网站源码下载了没有管理后台百度信息流广告怎么收费
  • 做网站需要找什么客户dsp投放方式
  • 烟台市铁路建设管理局网站百度推广平台有哪些
  • 网站制作公司武汉北京百度seo价格
  • 做电子商务网站 语言网站广告费一般多少钱
  • 昆明做网站推网站免费推广方式
  • 电商网站建设需求分析 实例题seo信息优化
  • 网站排名下降原因西安seo网络优化公司
  • 现在公众号做电影网站的发展爱站网关键词查询网站的工具
  • 做企业网站需要人维护么aso优化服务站
  • 免费网页设计作品深圳搜索引擎优化推广
  • 哪家网站建设做的好做百度推广效果怎么样
  • 做美陈网站网络营销师证书怎么考
  • 渝中网站公司网站seo是什么意思
  • 旅游网站怎样做网络宣传百度快照seo
  • 长春财经学院多大南宁网站seo排名优化
  • html5 素材网站百度推广培训班
  • 2015年做哪些网站致富网络营销推广案例
  • 容桂销售型网站建设建立一个网站需要多少钱?