Get Excel SheetNames using POI jar

softmage99 picture softmage99 · Sep 26, 2012 · Viewed 35.4k times · Source

I need all Excel sheet Names (what r all contains the datas) using POI jar. Like jxl jar - getSheetNames()

Answer

Gagravarr picture Gagravarr · Sep 26, 2012

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 = WorbookFactory.create(myFile);

List<String> sheetNames = new ArrayList<String>();
for (int i=0; i<wb.getNumberOfSheets(); i++) {
    sheetNames.add( wb.getSheetName(i) );
}