Extracting spreadsheet cells using Apache POI I'm working with Apache POI framework.

This code go through sheets, row and get value of cells. I will try to get value from directly indicated column. I need this because I want convert only some information from xls to csv.

FileOutputStream fos = new FileOutputStream(outputFile);

Workbook workbook = null;
for (File input : inputFile) {
  String ext = FilenameUtils.getExtension(input.toString());

  if (ext.equalsIgnoreCase("xlsx")) {
    workbook = new XSSFWorkbook(new FileInputStream(input));
  } else if (ext.equalsIgnoreCase("xls")) {
    workbook = new HSSFWorkbook(new FileInputStream(input));
  }

  int numberOfSheets = workbook.getNumberOfSheets();
  Row row;
  Cell cell;
  Sheet sheet = null;
  int[] kolumny = {1, 2, 3, 4, 5, 6, 7, 50, 51, 52, 53, 54, 55};

  for (int i = 1; i &lt; numberOfSheets; i++) {
    sheet = workbook.getSheetAt(i);
    if (sheet.getLastRowNum() &gt; 24) {
      Iterator&lt;Row&gt; rowIterator = sheet.iterator();
      while (rowIterator.hasNext()) {
        row = rowIterator.next();
        for (int j = 23; j &lt; sheet.getLastRowNum(); j++) {
          if (row.getRowNum() == j) {
            if (row.getCell(1) == null || row.getCell(1).getCellType() == Cell.CELL_TYPE_BLANK) {
              break;
            }
            Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
              cell = cellIterator.next();
              for (int kolumna : kolumny) {
                if (cell.getColumnIndex() == kolumna) {
                  if (cell != null) {
                    switch (cell.getCellType()) {
                      case Cell.CELL_TYPE_BOOLEAN:
                        data.append(cell.getBooleanCellValue() + ",");
                        break;
                      case Cell.CELL_TYPE_NUMERIC:
                        data.append(cell.getNumericCellValue() + ",");
                        break;
                      case Cell.CELL_TYPE_STRING:
                        data.append(cell.getStringCellValue() + ",");
                        break;
                      case Cell.CELL_TYPE_BLANK:
                        data.append("" + ",");
                        break;
                      default:
                        data.append(cell + ",");
                    }
                  }
                }
              }
            }
            data.append('\n');
          }
        }
      }
    }
  }
}
You could extract the content of inner loops to methods with speaking names.

E.g. You could introduce a method like 

public static void processSheet(Sheet sheet)
{
  if (sheet.getLastRowNum() &gt; 24) {
      Iterator&lt;Row&gt; rowIterator = sheet.iterator();
      while (rowIterator.hasNext()) {
        row = rowIterator.next();
  ...  

}


Within this method you can extract another method e.g. 

public static void processRow(Row row){
  for (int j = 23; j &lt; sheet.getLastRowNum(); j++) {
    if (row.getRowNum() == j) {
      if (row.getCell(1) == null || row.getCell(1).getCellType() == Cell.CELL_TYPE_BLANK) {
        break;
    ...       

}


And so on until you have only short methods with speaking names. This makes the code easier to read and understand.