Пример #1
0
  private Collection<Object[]> loadFromSpreadsheet(final InputStream excelFile) throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook(excelFile);

    data = new ArrayList<Object[]>();
    Sheet sheet = workbook.getSheetAt(0);

    int numberOfColumns = countNonEmptyColumns(sheet);
    List<Object[]> rows = new ArrayList<Object[]>();
    List<Object> rowData = new ArrayList<Object>();

    for (Row row : sheet) {
      if (isEmpty(row)) {
        break;
      } else {
        rowData.clear();
        for (int column = 0; column < numberOfColumns; column++) {
          Cell cell = row.getCell(column);
          rowData.add(objectFrom(workbook, cell));
        }
        rows.add(rowData.toArray());
      }
    }
    return rows;
  }
Пример #2
0
 private boolean isEmpty(final Row row) {
   Cell firstCell = row.getCell(0);
   boolean rowIsEmpty = (firstCell == null) || (firstCell.getCellType() == Cell.CELL_TYPE_BLANK);
   return rowIsEmpty;
 }