FileInputStream fis = new FileInputStream("data.xlsx");
Workbook workbook = new XSSFWorkbook(fis);
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
Cell cell1 = row.getCell(0);
Cell cell2 = row.getCell(1);
String value1 = cell1.getStringCellValue();
int value2 = (int) cell2.getNumericCellValue();
YourObject obj = new YourObject(value1, value2);
yourDAO.save(obj);
}
fis.close();
Workbook workbook = new XSSFWorkbook();
Row headerRow = sheet.createRow(0);
Cell headerCell1 = headerRow.createCell(0);
Cell headerCell2 = headerRow.createCell(1);
List<YourObject> dataList = yourService.getDataList();
int rowIndex = 1;
for (YourObject obj : dataList) {
Row row = sheet.createRow(rowIndex++);
Cell cell1 = row.createCell(0);
cell1.setCellValue(obj.getName());
Cell cell2 = row.createCell(1);
cell2.setCellValue(obj.getAge());
}
FileOutputStream fos = new FileOutputStream("report.xlsx");
workbook.write(fos);
fos.close();
FileInputStream fis = new FileInputStream("data.xlsx");
Workbook workbook = new XSSFWorkbook(fis);
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
Cell cell1 = row.getCell(0);
Cell cell2 = row.getCell(1);
if (cell1.getCellType() != CellType.STRING) {
}
}
}
fis.close();