SheetPivoter { static List<Cell> getDistinctValuesInSourceSheetColumn(Sheet sourceSheet, Integer columnNumber){ List<Cell> result = new ArrayList<>(); for (int i = SourceLayOut.VALUES_START_AT_ROWNUMBER; i <= sourceSheet.getLastRowNum(); i++){ Row r = sourceSheet.getRow(i); Cell c = r.getCell(columnNumber); boolean found = false; for (Cell cell : result){ if (PivotUtils.cellValueEquals(c, cell)){ found = true; continue; } } if (!found){ result.add(c); } } return result; }  void pivot(final Sheet pivotSourceSheet, final Sheet pivotTargetSheet);  }
@Test public void getDistinctValuesInSourceSheetColumnTest() { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); sheet.createRow(0).createCell(0).setCellValue("row"); sheet.createRow(1).createCell(0).setCellValue(1); sheet.createRow(2).createCell(0).setCellValue("fieldname"); List<Cell> l = p.getDistinctValuesInSourceSheetColumn(sheet, 0); Assertions.assertThat(l.size()).isEqualTo(0); sheet.createRow(3).createCell(0).setCellValue("a"); sheet.createRow(4).createCell(0).setCellValue("a"); sheet.createRow(5).createCell(0).setCellValue("b"); sheet.createRow(6).createCell(0).setCellValue(1); sheet.createRow(7).createCell(0).setCellValue(""); sheet.createRow(8).createCell(0); l = p.getDistinctValuesInSourceSheetColumn(sheet, 0); Assertions.assertThat(l.size()).isEqualTo(5); }