Code: Alles auswählen
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
// The following example code demonstrates how to get the Sheet
// names in an Excel spreadsheet file
public class GetExcelSheetNames {
public static void main(String[] args) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("C:/Users/test.xls");
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
// for each sheet in the workbook
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
System.out.println("Sheet name: " + workbook.getSheetName(i));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}