多页签导出

1.前端js

var datas = actives.getTableSelectedData()
if(datas&&datas.length>0){
    $.each(datas,function (index,value) {
        window.open(urls.listExport+"?declNo="+value.declNo + "&t="+index);
    })
}else {
    view.msg("请至少选择一行数据!")
}

2.后台逻辑

@RequestMapping(value = "/list_export")
public void ListExport(String declNo,HttpServletResponse response){
    try {
        Map data = new HashMap<>();
        DecHead decHead = decHeadAppService.loadDecHeadByDeclNo(declNo);
        String ieFlag = decHead.getIeFlag();
        List decLists = decListAppService.listDecListInfoByDeclNo(declNo);
        data.put("head",decHead);
        data.put("list",decLists);
        List containers = decContainAppService.listDecContainerBydeclNo(declNo);
        List decLicenseDocus = decLicenseDocuAppService.listDecLicenseDocuBydeclNo(declNo);
        Map containerMap = new HashMap<>();
        Map docuMap = new HashMap<>();
        containerMap.put("list",containers);
        docuMap.put("list",decLicenseDocus);
        Map> mapMap = new HashMap<>();
        mapMap.put(0,data);
        mapMap.put(1,containerMap);
        mapMap.put(2,docuMap);

         /*获取模板路径*/
        URL url =   ResourceUtils.getURL("classpath:exceltemplet/decListExport_"+ieFlag+".xls");
        FileUtils.downloadTemplates(url.getPath(),mapMap,"报关单明细"+declNo,response);
    }catch (Exception e){
        log.error(e.getMessage(),e);
        e.printStackTrace();
    }
}

3.工具类

public static void downloadTemplates(String path, Map> map, String fileName, HttpServletResponse response) {
    try {

        logger.info("路径:" + path);
        path = path.replaceAll("%20", " ");
        /*设置模板路径*/
        TemplateExportParams params = new TemplateExportParams(path, true);
        if (map == null) {
            map = new HashMap<>();
        }
        /*加载模板*/
        Workbook workbook = new ExcleExportUtil().createExcleByTemplate(params, map);
        /*设置返回表头*/
        response.setCharacterEncoding("UTF-8");
        response.setHeader("content-Type", "application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition",
            "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
        workbook.write(response.getOutputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

 

4.excel模板

多页签导出_第1张图片

多页签导出_第2张图片

 

多页签导出_第3张图片

 

你可能感兴趣的:(java)