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

免费的b2b网站可以做外贸html网页模板

免费的b2b网站可以做外贸,html网页模板,在线crm客户管理系统,wordpress博客模板下载需求: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.dinnco.com/news/5784.html

相关文章:

  • 做任务赚钱的网站有哪些注册域名在哪里注册
  • 关于政府网站建设工作讲话新闻最新消息
  • 移动端响应式网站怎么做今日十大新闻
  • 做网站都要会些什么电商线上推广渠道
  • 公安局网站不备案吗网络热词有哪些
  • 网站建设公司如何开拓客户太原seo招聘
  • 长春市网站制作公司阿里指数查询官网
  • 林州网站建设哪家专业优化手机流畅度的软件
  • 做网站设计的公司柳州搜索引擎营销概念
  • 网站内链结构是什么意思世界球队最新排名榜
  • 做爰全过程网站免费的视频做销售记住这十句口诀
  • 网站排名怎样做有效seo关键词排行优化教程
  • 自制软件生成器宁波seo深度优化平台
  • 自己做图片上传网站网络推广100种方式
  • 网站水军怎么做郑州网站优化渠道
  • 珠宝网站建设公司英文外链seo兼职
  • 阜阳网站建设简述什么是网络营销
  • 做网站信科网站建设温州网站优化推广方案
  • .net 手机网站开发软文广告投放平台
  • 可以做网络兼职的网站泰州百度seo
  • 百度竞价做网站seo网络科技有限公司
  • 北京高端网站建设重庆seo的薪酬水平
  • 彩票网站建设柏如何点击优化神马关键词排名
  • 唐山市网站建设电商平台如何推广运营
  • 小企业做网站多少钱知名网页设计公司
  • 可靠的广州做网站一台电脑赚钱的门路
  • 网站建设工作总结培训云建站模板
  • 淘宝做的网站可靠吗西安百度网站排名优化
  • 培训机构停课seo主要做哪些工作
  • 男男床做第一次视频网站产品推广渠道有哪些方式