Reputation: 35
I made poi excel read, upload and save into DB but when I check my DB, excel parsing db without first row. I tried to change code but it doesn't work so I put the my original code. please help!
public static List<Product> excelToExcelEntity(InputStream inputStream) {
try {
Workbook wb = new XSSFWorkbook(inputStream);
Sheet sheet = wb.getSheet(SHEET);
Iterator<Row> rows = sheet.iterator();
List<Product> entities = new ArrayList<Product>();
int rowNumber = 0;
while (rows.hasNext()) {
Row currentRow = rows.next();
if (rowNumber == 0) {
rowNumber++;
continue;
}
Iterator<Cell> cellsInRow = currentRow.iterator();
Product excelEntity = new Product();
DataFormatter formatter = new DataFormatter();
int cellIdx = 0;
while (cellsInRow.hasNext()) {
Cell currentCell = cellsInRow.next();
switch:
---
break;}
cellIdx++;
}
entities.add(excelEntity);
}
wb.close();
return entities;
Upvotes: 0
Views: 6635
Reputation: 103
if (rowNumber == 0) {
rowNumber++;
continue;
}
remove/comment above block code, in here continue will skip further execution and goes back to next element from the list, in your case it's skipping first row.
Upvotes: 1