1
votes

I have a Problem. I want to read the sheet name in a xlsx using XSSFWorkbook. I add external JARs in my Project: poi-3.9-jar poi-ooxml-3.11.jar xmlbeans-2.4.0.jar

private static String getSheetName(int page, String file) {
    FileInputStream fileInputStream = null;
    String name="";
    try {
        fileInputStream = new FileInputStream(file);
        System.out.println(file);
        Workbook workbook = new XSSFWorkbook(fileInputStream);
        System.out.println(workbook.getNumberOfSheets());
        name=workbook.getSheetName(page);

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return name;
}

But it throws always this Exception:

java.lang.NoClassDefFoundError: org/apache/poi/UnsupportedFileFormatException

Does anyone know what i forgot? Thanks!

2

2 Answers

3
votes

You are missing some jars.
Download the jars from the below link and add them to your project.
http://archive.apache.org/dist/poi/release/bin/poi-bin-3.9-20121203.zip

0
votes

I think you'd better use these dependencies:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.17</version>
</dependency>