缺少Java org.apache.poi.unsupportedfileformatexception

问题描述 投票:1回答:2

我有个问题。我想使用XSSFWorkbook在xlsx中读取工作表名称。我在我的项目中添加了外部JAR: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;
}

但它始终抛出此异常:

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

有谁知道我忘记了什么?谢谢!

java excel apache
2个回答
3
投票

你错过了一些罐子。 从以下链接下载罐子并将它们添加到您的项目中。 http://archive.apache.org/dist/poi/release/bin/poi-bin-3.9-20121203.zip


0
投票

我认为你最好使用这些依赖项:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.