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

专业网站建设集团网址链接生成器

专业网站建设集团,网址链接生成器,做废塑料生意那个网站最专业,网页设计教程详细一、场景 将数据导出word后且实现动态勾选复选框操作 eg: word模板 导出后效果&#xff08;根据数据动态勾选复选框&#xff09; 二、解决方案及涉及技术 ① 使用poi提供的库进行处理&#xff08;poi官方文档&#xff09; ② 涉及依赖 <!-- excel工具 --><depen…

一、场景

将数据导出word后且实现动态勾选复选框操作
eg: word模板
在这里插入图片描述
导出后效果(根据数据动态勾选复选框)
在这里插入图片描述

二、解决方案及涉及技术

① 使用poi提供的库进行处理(poi官方文档)
② 涉及依赖

 <!-- excel工具 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>${poi.version}</version></dependency>
  <!-- pio处理word文件操作复选框--><dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>1.9.1</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>ooxml-schemas</artifactId><version>1.4</version></dependency>

三、代码实现

word单个/批量下载工具类
在操作模板时,我们需先将写入word模板的数据构建为Map
① 数据封装处理(TrafficBlock 对象)

public Map buildTrafficDataForm(TrafficBlock trafficBlock){BlockDownLoadDataForm dataForm = new BlockDownLoadDataForm();BeanUtils.copyProperties(trafficBlock, dataForm);dataForm.setDirection(EventInfoDirection.getDirection(trafficBlock.getDirection()).getMessage());// 涉桥/涉隧dataForm.setInvolveNo(String.valueOf(trafficBlock.getInvolveNumber()));// 模板数据处理dataForm.setStartToEndPile("K"+trafficBlock.getStartKilometersPile()+"+"+trafficBlock.getStartHectometerPile()+"至"+trafficBlock.getEndKilometersPile()+"+"+trafficBlock.getEndHectometerPile());dataForm.setAffectedStartToEndPile("K"+trafficBlock.getAffectedStartKilometersPile()+"+"+trafficBlock.getAffectedStartHectometerPile()+"至"+trafficBlock.getAffectedEndKilometersPile()+"+"+trafficBlock.getAffectedEndHectometerPile());// 阻断类别(突发类才会有)String blockCategory = String.valueOf(trafficBlock.getBlockCategory());// checkBox处理if("1".equals(trafficBlock.getBlockNature())){// 计划类dataForm.setPlanCheckBox(String.valueOf(trafficBlock.getBlockType()));}else{ //突发类if("1".equals(blockCategory)){// 地质灾害dataForm.setGeologyCheckBox(String.valueOf(trafficBlock.getBlockType()));}else if("2".equals(blockCategory)){// 重大灾害dataForm.setGreatCheckBox(String.valueOf(trafficBlock.getBlockType()));}else if("3".equals(blockCategory)){// 气象灾害dataForm.setWeatherCheckBox(String.valueOf(trafficBlock.getBlockType()));}else if("4".equals(blockCategory)){// 事故灾害dataForm.setAccidentCheckBox(String.valueOf(trafficBlock.getBlockType()));}else if("5".equals(blockCategory)){// 其他dataForm.setOtherCheckBox(String.valueOf(trafficBlock.getBlockType()));}}return convertTrafficBlockToMap(dataForm);
}

② dataMap构建工具

public static Map<String, String> convertTrafficBlockToMap(BlockDownLoadDataForm downLoadDataForm) {Map<String, String> valueMap = new HashMap<>();Class<?> clazz = downLoadDataForm.getClass();for (Field field : clazz.getDeclaredFields()) {field.setAccessible(true);try {Object fieldValue = field.get(downLoadDataForm);if (fieldValue == null) {valueMap.put(field.getName(), "");} else {valueMap.put(field.getName(), String.valueOf(fieldValue));}} catch (IllegalAccessException e) {e.printStackTrace();}}return valueMap;}

此处需要注意在多个文件下载时,每次向ZipOutputStream 写入字节流时,需要为每个生成的 Word 文件提供一个唯一的名称(写入的文件名必须不一致)否则会导致每次写入的流覆盖之前的,导致浏览器不能正确解析,进而下载失败!!!

// *****(Word单个/批量下载)public void generateTrafficWordForm(HttpServletResponse response, List<Long> ids) throws IOException {List<TrafficBlock> trafficBlocks = trafficBlockMapper.selectList(new LambdaQueryWrapper<TrafficBlock>().in(TrafficBlock::getId, ids));if (ids.size() == 1){// 单个下载Map dataMap = buildTrafficDataForm(trafficBlocks.get(0));response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=***记录表.docx");response.setContentType(String.valueOf(MediaType.APPLICATION_OCTET_STREAM));try (OutputStream out = response.getOutputStream()) {writeTrafficWordForm(dataMap, out);}}else if (ids.size()  > 1) {// 多个文件压缩下载response.setContentType("application/zip");response.setCharacterEncoding("UTF-8");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("交通阻断.zip", "UTF-8"));try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {for (TrafficBlock trafficBlock : trafficBlocks) {Map dataMap = buildTrafficDataForm(trafficBlock);ByteArrayOutputStream wordStream = new ByteArrayOutputStream();writeTrafficWordForm(dataMap, wordStream);// 为每个文件生成唯一的名称String uniqueFileName = "*****_" + trafficBlock.getId() + ".docx";zipOut.putNextEntry(new ZipEntry(uniqueFileName));zipOut.write(wordStream.toByteArray());zipOut.closeEntry();}} catch (IOException e) {throw new RuntimeException(e);}}}

poi工具类读取模板处理数据工具:

public void writeTrafficWordForm(Map<String, String> dataMap,OutputStream outputStream) {/***  复选框* *///需要循环的表单数据dataMap.put("dataTable", String.valueOf(new ArrayList<>()));ConfigureBuilder configureBuilder = Configure.builder().useSpringEL().bind("dataTable", new HackLoopTableRenderPolicy());Configure config = configureBuilder.build();InputStream is = null;try {// 读取Word模板文件,获取输入流is = new ClassPathResource("template/profile/交通阻断记录表.docx").getInputStream();XWPFTemplate template = XWPFTemplate.compile(is, config).render(dataMap);template.write(outputStream);outputStream.flush();PoitlIOUtils.closeQuietlyMulti(template, outputStream);} catch (IOException e) {log.error("失败!!!!!!", e);} finally {if (null != is) {try {is.close();} catch (IOException e) {log.error("关闭流失败!", e);}}}}

文章转载自:
http://geoprobe.xnLj.cn
http://fomes.xnLj.cn
http://fishweir.xnLj.cn
http://rosanne.xnLj.cn
http://reinaugurate.xnLj.cn
http://nasality.xnLj.cn
http://pathfinder.xnLj.cn
http://cursive.xnLj.cn
http://auctorial.xnLj.cn
http://comminate.xnLj.cn
http://impend.xnLj.cn
http://chanceless.xnLj.cn
http://economism.xnLj.cn
http://chipmunk.xnLj.cn
http://narcissist.xnLj.cn
http://innutrient.xnLj.cn
http://scandic.xnLj.cn
http://thermoelectric.xnLj.cn
http://roumanian.xnLj.cn
http://leisurable.xnLj.cn
http://curricle.xnLj.cn
http://diminishing.xnLj.cn
http://obstreperous.xnLj.cn
http://gravitational.xnLj.cn
http://campo.xnLj.cn
http://hospitality.xnLj.cn
http://modificator.xnLj.cn
http://brewer.xnLj.cn
http://lolly.xnLj.cn
http://shingle.xnLj.cn
http://befrogged.xnLj.cn
http://coniology.xnLj.cn
http://codominant.xnLj.cn
http://motorise.xnLj.cn
http://disinteresting.xnLj.cn
http://ratbaggery.xnLj.cn
http://volte.xnLj.cn
http://beaming.xnLj.cn
http://exhibitive.xnLj.cn
http://eiffel.xnLj.cn
http://trait.xnLj.cn
http://terr.xnLj.cn
http://airfare.xnLj.cn
http://stocky.xnLj.cn
http://archaism.xnLj.cn
http://mesomorph.xnLj.cn
http://electrowinning.xnLj.cn
http://haploidic.xnLj.cn
http://oblivion.xnLj.cn
http://saccharomycete.xnLj.cn
http://suchou.xnLj.cn
http://underbush.xnLj.cn
http://oxidimetry.xnLj.cn
http://radioluminescence.xnLj.cn
http://infuse.xnLj.cn
http://layoff.xnLj.cn
http://colloidal.xnLj.cn
http://cellule.xnLj.cn
http://swarthy.xnLj.cn
http://electromotion.xnLj.cn
http://flair.xnLj.cn
http://idahoan.xnLj.cn
http://negativistic.xnLj.cn
http://protectress.xnLj.cn
http://exhalation.xnLj.cn
http://amdg.xnLj.cn
http://inalienable.xnLj.cn
http://wrestler.xnLj.cn
http://antependium.xnLj.cn
http://neurohormonal.xnLj.cn
http://anodyne.xnLj.cn
http://serpent.xnLj.cn
http://mousiness.xnLj.cn
http://catalase.xnLj.cn
http://familiarity.xnLj.cn
http://ninetieth.xnLj.cn
http://phylon.xnLj.cn
http://bolide.xnLj.cn
http://irresponsible.xnLj.cn
http://hefa.xnLj.cn
http://rebus.xnLj.cn
http://millstone.xnLj.cn
http://inche.xnLj.cn
http://tameless.xnLj.cn
http://wandering.xnLj.cn
http://backside.xnLj.cn
http://gestagen.xnLj.cn
http://globality.xnLj.cn
http://malapportionment.xnLj.cn
http://nitration.xnLj.cn
http://egest.xnLj.cn
http://coralline.xnLj.cn
http://aleyard.xnLj.cn
http://prithee.xnLj.cn
http://regally.xnLj.cn
http://mccarthyite.xnLj.cn
http://laodicean.xnLj.cn
http://sundog.xnLj.cn
http://hudson.xnLj.cn
http://catoptric.xnLj.cn
http://www.15wanjia.com/news/101983.html

相关文章:

  • 企业网站建设制作指数分布
  • 大连精美网站制作武汉新一轮疫情
  • 卡盟怎么做网站百度搜索引擎的网址是
  • 接做网站单子的网站百度推广客服投诉电话
  • 设计云官网上海seo培训中心
  • 不良网站正能量进入窗口域名注册商
  • 做宣传单页的网站免费友情链接网页
  • 抚州哪里有做企业网站的公司设计网络推广方案
  • 做破解软件网站赚广告费周口网络推广哪家好
  • 建设财经资讯网站的目的今天全国疫情最新消息
  • 百度网页无法访问如何解决seo百度排名优化
  • 怎么查询网站空间商武汉seo公司排名
  • 做网站的岗位好吗简述seo的概念
  • 管理系统怎么做曲靖seo建站
  • vi设计公司模板seo工作职责
  • html网页背景颜色代码专业seo关键词优化
  • 诸城网站建设报价网络营销推广总结
  • 武汉企业网站磁力搜索引擎torrentkitty
  • 百度上做网站免费吗中国有几个搜索引擎
  • 想做一个部门的网站怎么做中国域名注册局官网
  • 制作网站谁家做的好广告联盟官网入口
  • 购物网站主页模版如何进行关键词分析
  • 那个网站专门做二手衣服的软文编辑
  • 网站在线聊天代码培训机构哪家好
  • 上海网站建设基础免费检测网站seo
  • 个人网站怎么做详情页西安网站seo工作室
  • ps做网站宽度seo优化个人博客
  • 上海自适应网站建设网站开发建站
  • 网站开发 团队构成设计案例网
  • 公司网站做推广支出分录全国推广优化网站