• jxl写入excel实现数据导出功能


    @RequestMapping(params = "method=export", method = RequestMethod.GET)
        public void exportConfig(HttpServletRequest request, HttpServletResponse response,
                @RequestParam("dataId") String dataId, @RequestParam("group") String group,
                @RequestParam("querymethod") String querymethod ,ModelMap modelMap) {
           try{
               //根据传过来的dataId和group查出当前页面的配置
               Page<ConfigInfo> pageConfigInfo = new Page<ConfigInfo>();
               //判断是模糊查询还是查询,querymethod从前端传过来的志只能是findConfigInfoLike或者findConfigInfo,因此querymethod有Like就是模糊查询
               if(querymethod.indexOf("Like") > 0 )
                   pageConfigInfo = this.configService.findConfigInfoLike(MIN_PAGE_NUM, MAX_PAGE_SIZE, group, dataId);
               else
                   pageConfigInfo = this.configService.findConfigInfo(MIN_PAGE_NUM, MAX_PAGE_SIZE, group, dataId);
               List<ConfigInfo> listConfigInfo = new ArrayList<ConfigInfo>(); 
               if (null != pageConfigInfo)
                   listConfigInfo = pageConfigInfo.getPageItems();
               
               //创建文件
               String tempfileName = new String(FILE_NAME.getBytes("GBK"), "ISO8859_1");
               response.reset();
               //设定输出文件头
               response.setHeader("Content-disposition", "attachment; filename="+tempfileName);
               response.setContentType("application/x-msdownload");
               //取得输出流
               OutputStream outputStream = response.getOutputStream();
               //创建文件
               WritableWorkbook writableWorkbook = Workbook.createWorkbook(outputStream);
               //创建工作表对象
               WritableSheet writableSheet = writableWorkbook.createSheet(DEFAULT_SHEET, 0);
               //写入表头
               writableSheet.addCell(new Label(0, 0, "dataId"));
               writableSheet.addCell(new Label(1, 0, "group"));
               writableSheet.addCell(new Label(2, 0, "content"));
               //写入数据
               if(listConfigInfo!=null && !listConfigInfo.isEmpty()){
                   for(int i=0; i<listConfigInfo.size(); i++){
                       writableSheet.addCell(new Label(0, i+1, listConfigInfo.get(i).getDataId()));
                       writableSheet.addCell(new Label(1, i+1, listConfigInfo.get(i).getGroup()));
                       writableSheet.addCell(new Label(2, i+1, listConfigInfo.get(i).getContent()));
                   }
               }
               writableWorkbook.write();
               // 关闭工作簿
               writableWorkbook.close();
               outputStream.close();
           }catch(Exception e)
           {
               log.error("导出配置出错"+e);
           }
        }
  • 相关阅读:
    P1659 [国家集训队]拉拉队排练
    manacher小结
    P4555 [国家集训队]最长双回文串
    P3649 [APIO2014]回文串
    P3899 [湖南集训]谈笑风生
    插头dp练习
    luoguP3066 [USACO12DEC]逃跑的BarnRunning
    luoguP3769 [CH弱省胡策R2]TATT
    android 广播,manifest.xml注册,代码编写
    *.db-journal 是什么(android sqlite )数据库删除缓存
  • 原文地址:https://www.cnblogs.com/pwenlee/p/4849483.html
Copyright © 2020-2023  润新知