I need all Excel sheet Names (what r all contains the datas) using POI jar. Like jxl jar - getSheetNames()
Get Excel SheetNames using POI jar
Asked Answered
You don't say how you want them, so I'll guess at a list. You just need to iterate over the sheet indicies, getting the name for each. Your code would be something like:
File myFile = new File("/path/to/excel.xls");
Workbook wb = WorkbookFactory.create(myFile);
List<String> sheetNames = new ArrayList<String>();
for (int i=0; i<wb.getNumberOfSheets(); i++) {
sheetNames.add( wb.getSheetName(i) );
}
Is it possible to get excel sheet names without empty sheets.... As it is in JXL - getSheetNames()...... –
Graybeard
You'd have to get each sheet as you went, and check the row count on it. All depends on how you define an empty sheet! –
Luzon
FileInputStream fis = new FileInputStream("C:\Users\Usr\Desktop\TestData.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(fis);
int sheetcount = wb.getNumberOfSheets();
System.out.println("sheetcount: "+sheetcount);
for(int i=0; i<sheetcount;i++)
{
System.out.print(wb.getSheetName(i)+ " ");
}
© 2022 - 2024 — McMap. All rights reserved.