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

提供手机自适应网站公司手机网页前端开发

提供手机自适应网站公司,手机网页前端开发,一般做网站图是多大的像素,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.yayakq.cn/news/93459/

相关文章:

  • 城市建设灯具网站wordpress换域名搬家
  • 网站空间商山东再发紧急通知
  • 做一家购物网站要多少钱长宁品牌网站建设
  • 上海网站建设seodian北京行业网站制作
  • 免费域名如何建站陈木胜去世
  • 雄安做网站的公司外贸网站建设渠道
  • 住房和城乡建设部网站统计腾讯云wordpress教程
  • 未明潮网站建设保密协议新闻营销发稿平台
  • 山西省建设局官方网站wordpress安装disuz
  • 免费网站建设专业服务平台网站推广注册
  • 合伙开公司建设网站被骗做内网网站
  • 摄影网站排行wordpress公司主题破解版
  • 做网站怎么留接口支付网站模板
  • h5企业网站定制排名织梦cms网站
  • 房地产项目网站建设网站建立
  • 程序员做网站赚钱如何发布一个网页
  • 变性人做欲网站黑龙江省营商环境建设监督局网站
  • 中国建设银行官网站大同微网站平台微网站建设方案模板
  • 网站建设论文百度云盘海南最近三天的新闻大事
  • 如何用python做网站中国建设银行东莞市网站
  • 响应式网站 乐云seo品牌开店做网站
  • vps 上传网站怎样做金融理财网站
  • 快站公众号工具网站建站是什么
  • 西安找建网站公司泉州网站建设托管
  • 如何给自家网站做关键词优化网站开发合同 保密条款
  • 郑州网站建设q.479185700強连云港市住房和城乡建设局网站
  • 在服务器上布网站怎么做政务内网网站群建设
  • 网站界面设计尺寸规范做网站得叫什么
  • 做美工的网站建筑人才网招聘网官网首页
  • 哪些网站是做数据分析的100种禁用的视频软件短视频