1.sh.getLastRowNum() 比行数少1
private List<Map> getData(File file) throws Exception{ List<Map> list = new ArrayList<Map>(); //存放excel的data 每个list是sheet //获取IO流 BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); //打开HSSFWorkbook POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook wb = new HSSFWorkbook(fs);//获取HSSWorkbook int sheetsNum = wb.getNumberOfSheets();//excel sheet //解析sheet的数据 for(int i = 0 ; i < sheetsNum ; i++){ Map map = new HashMap(); HSSFSheet sh = wb.getSheetAt(i);//得到sheet //解析行 int columnNum = 0; for(int j = 0 ; j <= sh.getLastRowNum() ; j++){ HSSFRow row = sh.getRow(j); //解析列 for(int z = 0; z < row.getLastCellNum(); z++){ HSSFCell cell = row.getCell(z); if(cell != null){ if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){ map.put(j + "" + z, cell.getNumericCellValue()); } if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){ map.put(j + "" + z, cell.getStringCellValue()); } } } columnNum = row.getLastCellNum(); } if(sh.getLastRowNum() != 0 && columnNum != 0){ map.put("rowNum" ,sh.getLastRowNum() + 1); map.put("columnNum", columnNum); list.add(map); } } return list; }