poi 导出excel(简单demo)

 /**
     * 导出项目
     */
    @GetMapping(value = "/list/{name}/{txt}", consumes = "application/json")
    public BaseResponse download(@PathVariable String name, @PathVariable String txt) {
        Page page = new PageContext(1L, 10L);
        List list = managerService.getEnterpriseByNameExport(page, txt, name);
        /*List keyComplete = new ArrayList();
        keyComplete.add("QYMC");
        keyComplete.add("mainId");
        keyComplete.add("FDDBR");
        keyComplete.add("ZCZB");
        keyComplete.add("BZ");
        keyComplete.add("QYBQ");
        for (int i = 0; i < list.size(); i++) {
            Map map = (Map) list.get(i);
            if (map.size() < 6) {
                List listKey = new ArrayList();
                Iterator it = map.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next().toString();
                    listKey.add(key);
                }
                Collection exists = new ArrayList(keyComplete);
                list.remove(i);
                list.add(map.put(exists.removeAll(listKey), "-"));
            }

        }*/

        exportAccountData(list);
        return BaseResponse.success();
    }


    private void exportAccountData(List list) {

        try {
            HSSFWorkbook book = new HSSFWorkbook();
            HSSFSheet sheet = book.createSheet();

            Row rowFirst = sheet.createRow(0);
            Cell cell1 = rowFirst.createCell(0);
            cell1.setCellValue("企业名称");
            Cell cell2 = rowFirst.createCell(1);
            cell2.setCellValue("统一社会信用代码");
            Cell cell3 = rowFirst.createCell(2);
            cell3.setCellValue("法定代表人");
            Cell cell4 = rowFirst.createCell(3);
            cell4.setCellValue("注册资本");
            Cell cell5 = rowFirst.createCell(4);
            cell5.setCellValue("币种");
            Cell cell6 = rowFirst.createCell(5);
            cell6.setCellValue("企业标签 ");


            for (int i = 1; i < list.size(); i++) {
                Row row = sheet.createRow(i);
                for (int j = 65; j < 71; j++) {
                    Cell cell = row.createCell(j - 65);
                    Map map = (Map) list.get(i);
                    cell.setCellValue((String) map.get(String.valueOf((char) j)));
                }

                /*Map map = (Map) list.get(i);

                List listKey = new ArrayList();
                List listValue = new ArrayList();
                Iterator it = map.keySet().iterator();
                while (it.hasNext()) {
                    String key = it.next().toString();
                    listKey.add(key);
                    if (map.get(key).equals("") || map.get(key) == null) {
                        listValue.add("-");
                    } else {
                        listValue.add(map.get(key));
                    }
                }
                Set<Map.Entry<String, String>> entrySet = map.entrySet();

                for (int j = 0; j < listKey.size(); j++) {
                   *//* System.out.print("Key :" + listKey.get(i));
                    System.out.println(" Value :" +listValue.get(i) );*//*

                    Cell cell1 = row.createCell(j);
                    cell1.setCellValue(listValue.get(j).toString());

                }
                */
                /*for (int j = 0; j < entrySet.size(); j++) {
                    Cell cell1 = row.createCell(j);
                    cell1.setCellValue(1);
                }*/

                    /*for (Map.Entry<String, String> entry : entrySet) {
                        entry.getKey();
                        cell1.setCellValue(entry.getValue());
                    }*/
            }
            FileOutputStream fos = new FileOutputStream(new File("D:\\crms\\新建 XLS 工作表.xls"));

            book.write(fos);
            book.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值