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

电子网站建设网络公司seo推广

电子网站建设,网络公司seo推广,网站改版url,用wordpress做小程序需求:查询数据放入word模板中并在前端导出下载 解决方法:在模板的位置定义参数如 {{name}} {{age}}等等,使用 poi 处理 伪代码: PostMapping("/practiceAppr")public AjaxResult practiceAppr(OutputStream outputSt…

需求:查询数据放入word模板中并在前端导出下载

解决方法:在模板的位置定义参数如 {{name}}  {{age}}等等,使用 poi 处理

伪代码:

    @PostMapping("/practiceAppr")public AjaxResult practiceAppr(OutputStream outputStream, @RequestBody ExportToExcelParamDto paramDto) {//查询数据  ExportToWordByPracticeApprDto 为定义的模板中的参数ExportToWordByPracticeApprDto app= baseService.practiceApprExport(paramDto);try {//获取模板文件try (InputStream is = TrActivityGroupServiceImpl.class.getClassLoader().getResourceAsStream("word/导出模板A4.docx")) {try (XWPFDocument doc = new XWPFDocument(is)) {Map<String, Object> replaceMap = BeanUtil.beanToMap(app);Map<String, Object> resultMap = new HashMap<>();//word中的占位符格式是{{}}replaceMap.forEach((placeholder, replacement) -> resultMap.put("{{" + placeholder + "}}", replacement));//处理文件替换参数为实际值replacePlaceholders(doc, resultMap);doc.write(outputStream);outputStream.close();is.close();}}} catch (Exception e) {logger.error("文件导出错误{}", e.getMessage());}return null;}private void replacePlaceholders(XWPFDocument document, Map<String, Object> placeholders) throws IOException, InvalidFormatException {//处理普通word文字 不包含表格for (XWPFParagraph paragraph : document.getParagraphs()) {List<XWPFRun> runs = paragraph.getRuns();for (XWPFRun run : runs) {String text = run.getText(0);if (text != null) {for (Map.Entry<String, Object> entry : placeholders.entrySet()) {if (text.contains(entry.getKey())) {text = text.replace(entry.getKey(), entry.getValue() != null ? (String) entry.getValue() : "");run.setText(text, 0);}}}}}// 处理替换表格中的占位符for (XWPFTable table : document.getTables()) {for (XWPFTableRow row : table.getRows()) {for (XWPFTableCell cell : row.getTableCells()) {for (XWPFParagraph paragraph : cell.getParagraphs()) {List<XWPFRun> runs = paragraph.getRuns();for (XWPFRun run : runs) {String text = run.getText(0);if (text != null) {for (Map.Entry<String, Object> entry : placeholders.entrySet()) {if (text.contains(entry.getKey())) {//获取、处理图片略......int format = XWPFDocument.PICTURE_TYPE_PNG;//图片地址BufferedImage image = ImageIO.read(new URL(value));ByteArrayOutputStream outputStream = new ByteArrayOutputStream();//suffix为图片的后缀 .pngImageIO.write(image, suffix, outputStream);byte[] imageBytes = outputStream.toByteArray();//后两个参数是宽高run.addPicture(new ByteArrayInputStream(imageBytes), format, fileName, Units.toEMU(80), Units.toEMU(40));//替换文字  图片和文字如果都展示text = text.replace(entry.getKey(), entry.getValue() != null ? (String) entry.getValue() : "");run.setText(text, 0);}}}}}}}}}

最后前端处理进行下载即可。

http://www.hkea.cn/news/725566/

相关文章:

  • win7 网站配置优化方案官网电子版
  • 广州seo优化公司排名浙江seo博客
  • 全网推广的方式有哪些抖音seo推荐算法
  • 网站开发开源架构抖音营销软件
  • 自己做的网站能放到网上么青岛seo经理
  • 营业推广策划方案邵阳网站seo
  • 手机网站横向切换kol合作推广
  • 专门做超市海报的网站宁波seo咨询
  • 仿网站上的焦点图在线看seo网站
  • 做网站的业务员艾滋病阻断药有哪些
  • web集团网站建设广告投放平台有哪些
  • 大连做网站建设广告资源对接平台
  • 做网站怎么写工作日志泉州网站seo公司
  • wordpress外链站内打开搜索引擎是什么意思啊
  • 做论坛网站需要什么备案新站seo优化快速上排名
  • 动漫网站html百度网盘搜索
  • 怎么看一个网站什么语言做的宝鸡seo培训
  • 数据库网站建设公司他达拉非片
  • 英文商城网站建设搜索引擎营销的特点
  • 易优建站系统图片百度搜索
  • 网站开发不用框架web网站设计
  • 技能网站建设项目需求武汉网络推广外包公司
  • 安卓市场下载手机版优化网站排名技巧
  • 建设网站平台哪个好互联网营销外包推广
  • 工商注册企业名称查询广东seo网站推广代运营
  • 中纪委网站两学一做征文资源平台
  • java高端网站建设现在广告行业好做吗
  • wordpress 制作下载优化关键词怎么做
  • 宁波网站建设哪个公司好百度爱采购推广怎么入驻
  • 重庆市建设工程信息网特种作业企业网站seo多少钱