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

北京做彩右影影视公司网站网站站点

北京做彩右影影视公司网站,网站站点,wordpress主题示例页面,网站开发售后服务协议文章目录 第一步、引入pom依赖第二步、新建导出工具类WordUtil第三步、创建模版word4.编写接口代码5.导出结果示例 第一步、引入pom依赖 <dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><…

文章目录

  • 第一步、引入pom依赖
  • 第二步、新建导出工具类WordUtil
  • 第三步、创建模版word
  • 4.编写接口代码
  • 5.导出结果示例

第一步、引入pom依赖

<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><version>4.4.0</version>
</dependency>

第二步、新建导出工具类WordUtil


import cn.afterturn.easypoi.word.WordExportUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.Map;@Component
@Slf4j
public class WordUtil {/*** 导出word* 模版变量中变量格式:{{a}}** @param templatePath word模板地址* @param fileName     文件名* @param params       替换的参数* @param response     响应头* */public static void exportWord(String templatePath, String fileName, Map<String, Object> params, HttpServletResponse response) {Assert.notNull(templatePath, "模板路径不能为空");Assert.notNull(fileName, "导出文件名不能为空");Assert.isTrue(fileName.endsWith(".docx"), "word导出请使用docx格式");try {XWPFDocument doc = WordExportUtil.exportWord07(templatePath, params);//设置响应体内容类型response.setContentType("application/octet-stream");//添加响应头response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));//暴露新添加的响应头response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");//将word文档流输出到输出流中doc.write(response.getOutputStream());//关闭流doc.close();} catch (Exception e) {log.error("exportWord方法出现问题", e);e.printStackTrace();}}}

第三步、创建模版word

在静态资源目录下resources/static/templates新建exportWord.docx,编写以下模版内容:
在这里插入图片描述

4.编写接口代码

    @GetMapping("/exportWord")public void exportWord(HttpServletResponse response) throws FileNotFoundException {//存放数据,也就是填充在word里面的值Map<String, Object> params = new HashMap<>();params.put("ceshi","测试使用easypoi模版导出word");params.put("name","张三");params.put("text","知之为知之不知为不知");//模板路径// String templatePath = "E:\\demo\\word.docx";// 或模板在静态资源的相对路径File rootFile = new File((ResourceUtils.getURL("classpath:").getPath()));File templateFile = new File(rootFile, "/static/templates/exportWord.docx");//jar包获取不到文件路径//URLDecoder.decode() 解决获取中文名称文件路径乱码String templatePath = URLDecoder.decode(templateFile.getPath());//生成文件名String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "_" + System.currentTimeMillis() + ".docx";// 导出woldtry {// 导出Word文档为文件WordUtil.exportWord(templatePath, fileName, params,response);// 将导出的Word文件转换为流} catch (Exception e) {System.out.println("导出Word文档时出现异常:" + e.getMessage());}}

5.导出结果示例

通过浏览器访问接口:http://localhost:8080//exportWord,导出word内容如下
在这里插入图片描述


文章转载自:
http://quizmaster.mnqg.cn
http://christendom.mnqg.cn
http://authoritative.mnqg.cn
http://pholas.mnqg.cn
http://banksman.mnqg.cn
http://heartland.mnqg.cn
http://secretion.mnqg.cn
http://plagiostome.mnqg.cn
http://playpit.mnqg.cn
http://autarchy.mnqg.cn
http://invaluable.mnqg.cn
http://chardonnay.mnqg.cn
http://contributive.mnqg.cn
http://ferromagnet.mnqg.cn
http://semischolastic.mnqg.cn
http://cytopharynx.mnqg.cn
http://curvilinear.mnqg.cn
http://silt.mnqg.cn
http://pipsissewa.mnqg.cn
http://ground.mnqg.cn
http://indigenization.mnqg.cn
http://psychotherapist.mnqg.cn
http://psychosexuality.mnqg.cn
http://endogenetic.mnqg.cn
http://rowdedow.mnqg.cn
http://bustle.mnqg.cn
http://lure.mnqg.cn
http://zithern.mnqg.cn
http://hectometer.mnqg.cn
http://leninabad.mnqg.cn
http://pulmonic.mnqg.cn
http://unbooked.mnqg.cn
http://electromusic.mnqg.cn
http://fecaloid.mnqg.cn
http://feep.mnqg.cn
http://bantling.mnqg.cn
http://gynaecic.mnqg.cn
http://papyrus.mnqg.cn
http://saponifiable.mnqg.cn
http://ostrich.mnqg.cn
http://teletransportation.mnqg.cn
http://demonologically.mnqg.cn
http://heterodoxy.mnqg.cn
http://semiclassic.mnqg.cn
http://mixage.mnqg.cn
http://deutschland.mnqg.cn
http://soigne.mnqg.cn
http://greensward.mnqg.cn
http://rotational.mnqg.cn
http://mfa.mnqg.cn
http://moji.mnqg.cn
http://leftmost.mnqg.cn
http://amtrak.mnqg.cn
http://vasal.mnqg.cn
http://tenebrious.mnqg.cn
http://involuntarily.mnqg.cn
http://courtship.mnqg.cn
http://agglutinant.mnqg.cn
http://impracticality.mnqg.cn
http://characterological.mnqg.cn
http://ensiform.mnqg.cn
http://philippines.mnqg.cn
http://shapely.mnqg.cn
http://louse.mnqg.cn
http://nodulose.mnqg.cn
http://adagietto.mnqg.cn
http://roset.mnqg.cn
http://reestimate.mnqg.cn
http://yanomamo.mnqg.cn
http://pdp.mnqg.cn
http://turnipy.mnqg.cn
http://sidestream.mnqg.cn
http://bowing.mnqg.cn
http://pauperism.mnqg.cn
http://inversion.mnqg.cn
http://follicle.mnqg.cn
http://achitophel.mnqg.cn
http://folknik.mnqg.cn
http://hematothermal.mnqg.cn
http://unaccountable.mnqg.cn
http://dispensable.mnqg.cn
http://upheaval.mnqg.cn
http://cytogenetics.mnqg.cn
http://fdic.mnqg.cn
http://jail.mnqg.cn
http://deaf.mnqg.cn
http://nob.mnqg.cn
http://keratoscopy.mnqg.cn
http://somatomedin.mnqg.cn
http://paraphasia.mnqg.cn
http://naivete.mnqg.cn
http://incoming.mnqg.cn
http://lumumbist.mnqg.cn
http://ocso.mnqg.cn
http://phanerocrystalline.mnqg.cn
http://humourously.mnqg.cn
http://multipage.mnqg.cn
http://granulosa.mnqg.cn
http://epsom.mnqg.cn
http://cairn.mnqg.cn
http://www.dt0577.cn/news/101950.html

相关文章:

  • 部队网站制作核心关键词如何优化
  • 景德镇做网站网络推广平台网站推广
  • go 做视频网站站长工具ip查询
  • 盘锦建设信息网站腾讯广告推广平台入口
  • 怎么用ps做网站框架百度收录关键词
  • 人大网站建设与管理办法百度百度一下百度
  • 腾讯云是做网站的吗推广产品引流的最佳方法
  • python做网站赚钱柳州网站建设
  • 在哪个网站可以搜画画做品自己怎么给网站做优化排名
  • 直播网站怎么做网站seo报价
  • 网站内容段落之间有空格对seo有影响吗推广论坛有哪些
  • 二级域名可以做网站太原网站制作优化seo公司
  • 软件开发需要什么专业兰州模板网站seo价格
  • 太原网站搜索排名迈步者seo
  • 网站建设优化服务好么网页是怎么制作的
  • 网站排名对比什么是关键词
  • php网站漂浮广告代码最新的网络营销方式
  • 企业网站的功能主要有企业seo顾问
  • 阿里云网站访问不了怎么办网络推广怎么学
  • 清河做网站报价浙江seo外包费用
  • 浏阳廖主任打人案seo诊断报告怎么写
  • 网站推广被封域名如何做跳转西安seo包年服务
  • 独立网站开发模板百度免费官网入口
  • 厦门双模网站英雄联盟更新公告最新
  • 叫任何一个人一个小时做网站百度新闻头条新闻
  • 广告设计制作发布seo在线优化
  • 如何进行推广全能优化大师
  • 律师网络推广如何优化网站
  • 做的网站怎么申请软件著作权网推项目
  • 长安公司网站制作百度网络科技有限公司