Example usage for org.apache.poi.ss.usermodel Sheet getLastRowNum

List of usage examples for org.apache.poi.ss.usermodel Sheet getLastRowNum

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet getLastRowNum.

Prototype

int getLastRowNum();

Source Link

Document

Gets the last row on the sheet Note: rows which had content before and were set to empty later might still be counted as rows by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be higher than expected!

Usage

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void guquanbiangeng(Hcrw hcrw, Sheet sheetGQBG, Integer nd) {
    try {//from w  w w.j  a va 2 s  . c  o m
        stockRightChangeMapper.deleteByTaskIdNd(hcrw.getId(), nd);
        // 
        int rowNum = sheetGQBG.getLastRowNum();
        for (int i = 6; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(2)).trim().equals("")) {
                StockRightChange stockRightChange = new StockRightChange();
                stockRightChange.setId(UUID.randomUUID().toString().replace("-", ""));
                stockRightChange.setNd(nd);
                stockRightChange.setXydm(hcrw.getHcdwXydm());
                stockRightChange.setGd(POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(2)));
                stockRightChange.setBgqGqbl(
                        parseFloat(POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(3))) * 100);
                stockRightChange.setBghGqbl(
                        parseFloat(POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(4))) * 100);
                stockRightChange.setBgrq(POIUtils.getStringCellValue(sheetGQBG.getRow(i).getCell(5)));
                stockRightChangeMapper.insert2(stockRightChange);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ???? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[????]??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void duiwaitouzi(Hcrw hcrw, Sheet sheetDWTZ, Integer nd) {
    try {/*from  w  w w .  j ava 2  s .co m*/
        investmentMapper.deleteByTaskIdNd(hcrw.getId(), nd);
        // 
        int rowNum = sheetDWTZ.getLastRowNum();
        for (int i = 5; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheetDWTZ.getRow(i).getCell(3)).trim()
                    && !POIUtils.getStringCellValue(sheetDWTZ.getRow(i).getCell(3)).trim().equals("")) {
                Investment investment = new Investment();
                investment.setId(UUID.randomUUID().toString().replace("-", ""));
                investment.setNd(nd);
                investment.setXydm(hcrw.getHcdwXydm());
                investment.setTzqymc(POIUtils.getStringCellValue(sheetDWTZ.getRow(i).getCell(2)));
                investment.setTzqyZch(POIUtils.getStringCellValue(sheetDWTZ.getRow(i).getCell(3)));
                investmentMapper.insert2(investment);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ????? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[?????]??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void duiwandanbao(Hcrw hcrw, Sheet sheetDWDB, Integer nd) {
    try {/*from w ww.  j  ava  2s. co  m*/
        guaranteeMapper.deleteByTaskIdNd(hcrw.getId(), nd);
        // 
        int rowNum = sheetDWDB.getLastRowNum();
        for (int i = 5; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(2)).trim().equals("")) {
                Guarantee guarantee = new Guarantee();
                guarantee.setId(UUID.randomUUID().toString().replace("-", ""));
                guarantee.setNd(nd);
                guarantee.setXydm(hcrw.getHcdwXydm());
                guarantee.setZqr(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(2)));
                guarantee.setZwr(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(3)));
                guarantee.setZzqzl(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(4)));
                guarantee.setZzqse(parseFloat(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(5))));
                guarantee.setLxzwqx(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(6)));
                guarantee.setBzqj(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(7)));
                guarantee.setBzfs(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(8)));
                guarantee.setBzdbfw(POIUtils.getStringCellValue(sheetDWDB.getRow(i).getCell(9)));
                guaranteeMapper.insert2(guarantee);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[??]??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void xingzhengxuke(Hcrw hcrw, Sheet sheetXZXK, Integer nd) {
    try {/*from www  . j  a v  a2  s .c  o m*/
        licenseMapper.deleteByTaskIdNd(hcrw.getId(), nd);
        // 
        int rowNum = sheetXZXK.getLastRowNum();
        for (int i = 5; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheetXZXK.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheetXZXK.getRow(i).getCell(2)).trim().equals("")) {
                License license = new License();
                license.setId(UUID.randomUUID().toString().replace("-", ""));
                license.setNd(nd);
                license.setXydm(hcrw.getHcdwXydm());
                license.setXkwjmc(POIUtils.getStringCellValue(sheetXZXK.getRow(i).getCell(3)));
                license.setYxq(POIUtils.getStringCellValue(sheetXZXK.getRow(i).getCell(4)) + "-"
                        + POIUtils.getStringCellValue(sheetXZXK.getRow(i).getCell(5)));
                licenseMapper.insert2(license);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?????? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[??????]??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void jsGudongchuzhi(Hcrw hcrw, Sheet sheet) throws Exception {
    try {/*from   w  w  w.  j av a 2  s .  co  m*/
        jsStockholderContributionMapper.deleteByTaskId2(hcrw.getId());
        // 
        int rowNum = sheet.getLastRowNum();
        for (int i = 6; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim().equals("")) {
                JsStockholderContribution jsStockholderContribution = new JsStockholderContribution();
                jsStockholderContribution.setId("");
                jsStockholderContribution.setXydm(hcrw.getHcdwXydm());
                jsStockholderContribution.setGd(POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)));
                jsStockholderContribution
                        .setBgrq(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4))));
                jsStockholderContribution.setRje(null);
                jsStockholderContribution
                        .setSje(new BigDecimal(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3))));
                jsStockholderContribution.setGssj(null);
                jsStockholderContribution.setRjczfs(null);
                jsStockholderContribution.setRjcze(null);
                jsStockholderContribution.setRjczrq(null);
                jsStockholderContribution.setSjczfs(POIUtils.getStringCellValue(sheet.getRow(i).getCell(5)));
                jsStockholderContribution
                        .setSjcze(new BigDecimal(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3))));
                jsStockholderContribution
                        .setSjczrq(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4))));
                jsStockholderContributionMapper.insert2(jsStockholderContribution);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?? ? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[??](?)??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void jsGuquanbiangeng(Hcrw hcrw, Sheet sheet) throws Exception {
    try {//www  .  j  a  v  a 2s.  c  o  m
        jsGqbgMapper.deleteByTaskId2(hcrw.getId());
        // 
        int rowNum = sheet.getLastRowNum();
        for (int i = 6; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim().equals("")) {
                JsGqbg jsGqbg = new JsGqbg();
                jsGqbg.setId("");
                jsGqbg.setXydm(hcrw.getHcdwXydm());
                jsGqbg.setGd(POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)));
                jsGqbg.setBgrq(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(5))));
                jsGqbg.setBgqbl(new BigDecimal(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3))));
                jsGqbg.setBghbl(new BigDecimal(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4))));
                jsGqbg.setGssj(null);
                jsGqbgMapper.insert2(jsGqbg);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ???? ? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException(
                "[????](?)??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void jsXingzhengchufa(Hcrw hcrw, Sheet sheet) throws Exception {
    try {/*w ww  .j a va2  s.  c om*/
        jsXzcfMapper.deleteByTaskId2(hcrw.getId());
        // 
        int rowNum = sheet.getLastRowNum();
        for (int i = 6; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim().equals("")) {
                JsXzcf jsXzcf = new JsXzcf();
                jsXzcf.setId("");
                jsXzcf.setXydm(hcrw.getHcdwXydm());
                jsXzcf.setXzcfjdswh(POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)));
                jsXzcf.setWflx(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3)));
                jsXzcf.setXzcfnr(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4)));
                jsXzcf.setCfjg(POIUtils.getStringCellValue(sheet.getRow(i).getCell(5)));
                jsXzcf.setCfrq(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(6))));
                jsXzcf.setBz(null);
                jsXzcf.setGssj(null);
                jsXzcfMapper.insert2(jsXzcf);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?? ? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[??](?)??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void jsXingzhengxuke(Hcrw hcrw, Sheet sheet) throws Exception {
    try {/*from   w w w.ja v  a 2s .c om*/
        jsLicenseMapper.deleteByTaskId2(hcrw.getId());
        // 
        int rowNum = sheet.getLastRowNum();
        for (int i = 5; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim().equals("")) {
                JsLicense jsXjsLicensecf = new JsLicense();
                jsXjsLicensecf.setId("");
                jsXjsLicensecf.setXydm(hcrw.getHcdwXydm());
                jsXjsLicensecf.setXkwjbh(POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)));
                jsXjsLicensecf.setXkwjmc(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3)));
                jsXjsLicensecf.setYxqKs(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4))));
                jsXjsLicensecf.setYxqJs(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(5))));
                jsXjsLicensecf.setXkjg(POIUtils.getStringCellValue(sheet.getRow(i).getCell(6)));
                jsXjsLicensecf.setXknr("");
                jsXjsLicensecf.setZt(POIUtils.getStringCellValue(sheet.getRow(i).getCell(7)));
                jsXjsLicensecf.setXq(null);
                jsXjsLicensecf.setHdrq(null);
                jsXjsLicensecf.setGssj(null);
                jsLicenseMapper.insert2(jsXjsLicensecf);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?????? ? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException(
                "[??????](?)??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

private void jsZhishichanquan(Hcrw hcrw, Sheet sheet) throws Exception {
    try {//from   w  w w .  j  a v a2 s  .  c  om
        jsZscqMapper.deleteByTaskId2(hcrw.getId());
        // 
        int rowNum = sheet.getLastRowNum();
        for (int i = 5; i < rowNum; i++) {
            if (null != POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim()
                    && !POIUtils.getStringCellValue(sheet.getRow(i).getCell(2)).trim().equals("")) {
                JsZscq jsZscq = new JsZscq();
                jsZscq.setId("");
                jsZscq.setXydm(hcrw.getHcdwXydm());
                jsZscq.setQymc(POIUtils.getStringCellValue(sheet.getRow(i).getCell(3)));
                jsZscq.setZl(POIUtils.getStringCellValue(sheet.getRow(i).getCell(4)));
                jsZscq.setCzrmc(POIUtils.getStringCellValue(sheet.getRow(i).getCell(5)));
                jsZscq.setZqrmc(POIUtils.getStringCellValue(sheet.getRow(i).getCell(6)));
                jsZscq.setZqdjrq(getDateValue(POIUtils.getStringCellValue(sheet.getRow(i).getCell(7))));
                jsZscq.setZt(POIUtils.getStringCellValue(sheet.getRow(i).getCell(8)));
                jsZscq.setBhqk(POIUtils.getStringCellValue(sheet.getRow(i).getCell(9)));
                jsZscq.setGssj(null);
                jsZscqMapper.insert2(jsZscq);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        MongoLogger.warn("?? ?? ? ",
                ExceptionUtils.getStackTrace(e), hcrw.getId());
        throw new RuntimeException("[??](?)??;");
    }
}

From source file:com.kysoft.cpsi.audit.service.SelfCheckServiceImpl.java

@Override
public void judgeRepeatExcle(InputStream is, int firstRowNum, int colNum, String fileName) throws Exception {
    Map<String, Object> sheetValues = new HashedMap();
    Workbook workbook = null;//from   w  w  w  .ja va 2 s . com
    if (fileName.endsWith("xls")) {
        POIFSFileSystem fs = new POIFSFileSystem(is);
        workbook = new HSSFWorkbook(fs);
    } else if (fileName.endsWith("xlsx")) {
        workbook = new XSSFWorkbook(is);
    }
    Sheet sheet = workbook.getSheetAt(0);
    for (int i = firstRowNum; i < sheet.getLastRowNum() + 1; i++) {
        Row row = sheet.getRow(i - 1);
        System.out.println(i);
        Cell cell = row.getCell(colNum - 1);
        if (null != cell && null != POIUtils.getStringCellValue(cell)
                && !POIUtils.getStringCellValue(cell).equals("")) {
            if (sheetValues.containsKey(POIUtils.getStringCellValue(cell))) {
                throw new RuntimeException(
                        POIUtils.getStringCellValue(cell) + "??????");
            } else {
                sheetValues.put(POIUtils.getStringCellValue(cell), i);
            }
        }
    }
}