Excel 获取数据 / jxl-2.6.10.jar | log4j-1.2.14.jar

 

private String initial() throws BiffException, IOException {

        Workbook book = Workbook.getWorkbook(new File(file));

        Sheet[] sheets = book.getSheets();

        for (Sheet sheet : sheets) {

            if("Sheet1".equalsIgnoreCase(sheet.getName().trim())) {

                for(int j=2; j<sheet.getRows(); j++) {

                    Cell cell = sheet.getCell(0, j);

                    String planCode = cell.getContents().trim();

                    String tranche = sheet.getCell(1, j).getContents().trim();

                    String region = sheet.getCell(2, j).getContents().trim();

                    String channel = sheet.getCell(3, j).getContents().trim();

                    String branchCode = sheet.getCell(4, j).getContents().trim();

                    String effectiveDateStr = sheet.getCell(6, j).getContents().trim();

                    

                    Calendar startDate = Calendar.getInstance();

                    startDate.set(Calendar.YEAR, Integer.parseInt(effectiveDateStr.substring(0, 4)));

                    startDate.set(Calendar.MONTH, Integer.parseInt(effectiveDateStr.substring(4, 5)));

                    startDate.set(Calendar.DAY_OF_MONTH, Integer.parseInt(effectiveDateStr.substring(6, 7)));

                    startDate.set(Calendar.MINUTE, 0);

                    startDate.set(Calendar.SECOND, 0);

                    startDate.set(Calendar.HOUR_OF_DAY, 0);

                    

                    String expiryDateStr = sheet.getCell(7, j).getContents().trim();

                    Calendar endDate = Calendar.getInstance();

                    endDate.set(Calendar.YEAR, Integer.parseInt(expiryDateStr.substring(0, 4)));

                    endDate.set(Calendar.MONTH, Integer.parseInt(expiryDateStr.substring(4, 5)));

                    endDate.set(Calendar.DAY_OF_MONTH, Integer.parseInt(expiryDateStr.substring(6, 7)));

                    endDate.set(Calendar.MINUTE, 0);

                    endDate.set(Calendar.SECOND, 0);

                    endDate.set(Calendar.HOUR_OF_DAY, 0);

                    

//                    if(products.size() > 0) {

//                        Product lastProduct = products.get(products.size() - 1);

//                        if(planCode.equals(lastProduct.getPlanCode())) {

//                            System.out.println("已存在的产品");

//                        }

//                    }

                    

                    Product product = new Product();

                    product.setPlanCode(planCode);

                    product.setBranchCode(branchCode);

                    product.setChannel(channel);

                    product.setRegion(region);

                    product.setTranche(tranche);

                    product.setEffectiveDate(startDate.getTime());

                    product.setExpiryDate(endDate.getTime());

                    products.add(product);

                }

            }

        }

        book.close();

        return "";

    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值