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

外贸网站seo有哪些公司郑州全域静态管理

外贸网站seo有哪些公司,郑州全域静态管理,公司网站建设ppt,网站服务器做缓存吗需求:Java查询多条数据放入word模板 多个word文件处理成zip压缩包并在前端下载.zip文件 解决方法:在模板的位置定义参数如 {{name}} {{age}}等等,使用 poi 处理 伪代码: PostMapping("/exportPracticeAppr")public S…

 需求:Java查询多条数据放入word模板 多个word文件处理成zip压缩包并在前端下载.zip文件

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

伪代码:

    @PostMapping("/exportPracticeAppr")public String exportPracticeAppr(HttpServletResponse response, @RequestBody ExportToExcelParamDto paramDto) throws IOException {//查询数据 ExportToWordByPracticeApprDto为模板中的参数List<ExportToWordByPracticeApprDto> practiceApprExport = baseService.practiceApprExport(paramDto);if (practiceApprExport != null && !practiceApprExport.isEmpty()) {// 创建一个zip文件,并打开一个ZipOutputStream来写入文件FileOutputStream fos = new FileOutputStream(paramDto.getActivityName() + "demo.zip");ZipOutputStream zos = new ZipOutputStream(fos);try {//获取word模板文件InputStream resourceAsStream = TrActivityGroupServiceImpl.class.getClassLoader().getResourceAsStream("word/导出模板.docx");XWPFDocument doc = new XWPFDocument(Objects.requireNonNull(resourceAsStream));//循环处理文件for (ExportToWordByPracticeApprDto apprDto : practiceApprExport) {Map<String, Object> replaceMap = BeanUtil.beanToMap(apprDto);Map<String, Object> resultMap = new HashMap<>();replaceMap.forEach((placeholder, replacement) -> resultMap.put("{{" + placeholder + "}}", replacement));replacePlaceholders(doc, resultMap);// 将Word文档保存为临时文件File tempFile = File.createTempFile("demo", DOCX);FileOutputStream tempOut = new FileOutputStream(tempFile);doc.write(tempOut);tempOut.close();// 将临时文件添加到zip文件中  表示压缩包中的文件名称 aa.docxZipEntry zipEntry = new ZipEntry("aa.docx");zos.putNextEntry(zipEntry);FileInputStream fis = new FileInputStream(tempFile);IOUtils.copy(fis, zos);fis.close();zos.closeEntry();tempFile.delete();}// 关闭zip文件输出流zos.close();doc.close();} catch (Exception e) {logger.error("文件导出错误{}", e.getMessage());}}// 返回zip文件内容byte[] zipBytes = IOUtils.toByteArray(Files.newInputStream(Paths.get("demo.zip")));response.reset();response.setContentType("application/zip");response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("demo.zip", "UTF-8"));response.setContentLength(zipBytes.length);OutputStream out = response.getOutputStream();out.write(zipBytes);out.flush();out.close();return "redirect:/";}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/508180/

相关文章:

  • 网站开发者排名开发一个app平台大概需要多少钱?
  • 做网站 博客百度推广助手客户端
  • 温州市手机网站制作哪家好爱站网长尾词挖掘
  • 党委网站建设要求凡科建站靠谱吗
  • wordpress 安卓客户端福建seo优化
  • 襄阳seo技术长沙seo网站优化
  • 做一的同志小说网站做seo要投入什么
  • 网站的文件结构百度搜索排名怎么收费
  • 全景网站app网络营销工具分析
  • 南京建设工程交易中心网站seo是什么的简称
  • 利用vps做网站关键字排名查询
  • 常熟网站制作找哪家好品牌型网站制作价格
  • 怎么做自己网站推广网络广告
  • 化州网站建设促销方法100种
  • 长沙专业网站设计平台新闻最新消息10条
  • 惠州网站建设制作宣传推广方案
  • 宁波网站推广外包服务长岭网站优化公司
  • 哈尔滨市哪里做淘宝网站seo课程心得体会
  • 做网站建设公司企业一个企业该如何进行网络营销
  • 移动端h5网站开发服务企业seo推广
  • 管理公司网站建设引擎搜索优化
  • 上市公司专利查询网站百度广告投放价格
  • html5电商网页制作网站怎么seo关键词排名优化推广
  • 大同网站建设黄冈网站推广优化找哪家
  • 昌邑网站建设站长之家网站排名
  • 建设企业网站的需求分析免费域名
  • 重庆欧勒精细有限公司网站策划书百度竞价推广开户
  • 怎么做一键添加信任网站ios aso优化工具
  • ps做网站的分辨率多少钱苹果cms永久免费建站程序
  • 网站推广积分常用于网站推广的营销手段是