在文件上传中,需要对excel中的空白行进行处理,但jxl中没有提供。自己增加的方法如下:

 
  
  1. private int getRightRows(Sheet sheet) { 
  2. int rsCols = sheet.getColumns(); //列数 
  3. int rsRows = sheet.getRows(); //行数 
  4. int nullCellNum; 
  5. int afterRows = rsRows; 
  6. for (int i = 1; i < rsRows; i++) { //统计行中为空的单元格数 
  7.    nullCellNum = 0
  8.     for (int j = 0; j < rsCols; j++) { 
  9.         String val = sheet.getCell(j, i).getContents(); 
  10.         val = StringUtils.trimToEmpty(val); 
  11.         if (StringUtils.isBlank(val)) 
  12.            nullCellNum++; 
  13.     } 
  14.     if (nullCellNum >= rsCols) { //如果nullCellNum大于或等于总的列数 
  15.      afterRows--;          //行数减一 
  16.    } 
  17. return afterRows;