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 < numberOfSheets; i++) {
sheet = workbook.getSheetAt(i);
if (sheet.getLastRowNum() > 24) {
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
row = rowIterator.next();
for (int j = 23; j < sheet.getLastRowNum(); j++) {
if (row.getRowNum() == j) {
if (row.getCell(1) == null || row.getCell(1).getCellType() == Cell.CELL_TYPE_BLANK) {
break;
}
Iterator<Cell> 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');
}
}
}
}
}
}
Workbook
,XSSFWorkbook
and the rest come from? \$\endgroup\$