Java 无法解决import org.apache.poi.xssf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26829424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:21:39  来源:igfitidea点击:

The import org.apache.poi.xssf can not be resolved

javaexcelapachemaven

提问by TDHM

I've created Maven project and in pom.xml, I've mentioned following POI dependency in order to read from and write to excel file:

我已经创建了 Maven 项目,在 pom.xml 中,为了读取和写入 excel 文件,我提到了以下 POI 依赖项:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.9</version>
    </dependency>

In test, when I add import org.apache.poi.hssf.usermodel.HSSFWorkbook;, I don't see any error.

在测试中,当我添加时import org.apache.poi.hssf.usermodel.HSSFWorkbook;,我没有看到任何错误。

However when I add import org.apache.poi.xssf.usermodel.XSSFWorkbook;, it shows an error: The import org.apache.poi.xssf can not be resolved

但是,当我添加时import org.apache.poi.xssf.usermodel.XSSFWorkbook;,它显示一个错误:The import org.apache.poi.xssf can not be resolved

It's throwing error for XSSF but not for HSSF. Can you guide me how to resolve this issue?

它为 XSSF 抛出错误,但不为 HSSF 抛出错误。你能指导我如何解决这个问题吗?

采纳答案by geert3

for Poi/XSSF you need also dependency to poi-ooxml, like so

对于 Poi/XSSF,您还需要依赖于poi-ooxml,就像这样

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

回答by yTze

Look for "poi-3.17.jar"!!!

寻找“poi-3.17.jar”!!!

  1. Download from "https://poi.apache.org/download.html".
  2. Click the one Binary Distribution -> poi-bin-3.17-20170915.tar.gz
  3. Unzip the file download and look for this "poi-3.17.jar".
  1. 从“ https://poi.apache.org/download.html”下载。
  2. 单击一个 Binary Distribution -> poi-bin-3.17-20170915.tar.gz
  3. 解压缩文件下载并查找此“poi-3.17.jar”。

Problem solved and errors disappeared.

问题解决,错误消失。

Hope this could help.

希望这会有所帮助。

回答by Pooja

When using maven, for Apache POI, make sure to add all the latest dependencies related to Apache POI as follows:

使用 maven 时,对于 Apache POI,请确保添加所有与 Apache POI 相关的最新依赖项,如下所示:

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

<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>3.1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-scratchpad</artifactId>
    <version>4.1.0</version>
</dependency>

Save and run. Errors should be resolved.

保存并运行。应该解决错误。