I just have a quick question about how to read in an xlsx file using the XSSF format from Apache.
Right now my code looks like this:
InputStream fs = ne
InputStream inp = null;
try {
inp = new FileInputStream("E:/sample_poi.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Header header = sheet.getHeader();
int rowsCount = sheet.getLastRowNum();
System.out.println("Total Number of Rows: " + (rowsCount + 1));
for (int i = 0; i <= rowsCount; i++) {
Row row = sheet.getRow(i);
int colCounts = row.getLastCellNum();
System.out.println("Total Number of Cols: " + colCounts);
for (int j = 0; j < colCounts; j++) {
Cell cell = row.getCell(j);
System.out.println("[" + i + "," + j + "]=" + cell.getStringCellValue());
}
}
} catch (Exception ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
inp.close();
} catch (IOException ex) {
java.util.logging.Logger.getLogger(FieldController.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Load sheet- Here we are loading first sheet only
XSSFSheet xlSheet = wb.getSheetAt(0);
Here code recognizing only first sheet - In my Excel multiple sheets are there so facing problem to change sheet2
to sheet1(getSheetAt(0))
...