Java查出的数据生成word

 /**
     * 返回申请单给前端
     * //     * @param args
     * @throws Exception
     */
    @GetMapping({"viewSupplyDetail/{id}"})
    @ApiOperation("返回多个附件给前端")
    @ResponseBody
    public void viewDetail(@PathVariable String id, HttpServletResponse response) throws IOException {
        InputStream is = null;
        TechOrdDTO byPrimaryKey = this.baseService.getByPrimaryKey(id);
//        byPrimaryKey.setProjectName(SecurityExtUtils.getCurrentLoginUser(getRequest()).getString("projectName"));
        //获取模板文档
        is = new ClassPathResource("/exportTemplate/technical_order.docx").getInputStream();

        //填充数据
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(byPrimaryKey.getTraList())) {
            //节点状态类型翻译
            AbstractDictUtils.dictFormatOfCollection(byPrimaryKey.getTraList(),
                    new String[]{CommunalConstants.DictType.NOD_STU},
                    new String[]{CommunalConstants.ClassFieldName.NODE_STATUS},
                    new String[]{CommunalConstants.ClassFieldName.NODE_STATUS});
            for (TechTrackingDTO tracking : byPrimaryKey.getTraList()) {
                Map<String, Object> resultListParams = new HashMap<>();
                resultListParams.put("nodeName", tracking.getNodeName());
                resultListParams.put("stu", tracking.getStu());
                resultListParams.put("comment", tracking.getComment());
                resultListParams.put("createTime", DateUtils.format(tracking.getCreateTime(), "yyyy年MM月dd日"));
                resultListParams.put("createName", tracking.getCreateName());
                resultList.add(resultListParams);
            }
        }

        //准备数据
        Map<String, Object> params = new HashMap<>();
        params.put("data", resultList);
        params.put("projectName", byPrimaryKey.getProjectName());
        //维修类型翻译
        AbstractDictUtils.singleDictFormat(byPrimaryKey, CommunalConstants.DictType.MAINTAIN_TYPE,
                CommunalConstants.ClassFieldName.MAINTAIN, CommunalConstants.ClassFieldName.MAINTAIN);

        params.put("type", byPrimaryKey.getType());
        params.put("depName", byPrimaryKey.getDepName());
        params.put("userName", byPrimaryKey.getUserName());
        params.put("summarize", byPrimaryKey.getSummarize());

        LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
        Configure config = Configure.builder().bind("data", hackLoopTableRenderPolicy).build();

        XWPFTemplate template = XWPFTemplate.compile(is, config).render(params);

        // 文件下载
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + System.currentTimeMillis() + ".docx");
        ServletOutputStream outputStream = response.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(outputStream);
        template.write(bos);
        bos.flush();
        outputStream.flush();
        PoitlIOUtils.closeQuietlyMulti(template, bos, outputStream);

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值