无法在 Apache POI 中导入 XSSF

发布于 2024-11-04 14:17:22 字数 254 浏览 0 评论 0原文

我正在引用 Apache POI 的 3.7 版本,并且在执行此操作时收到“无法解析”错误:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

引用 POI 的其他导入语句不会给我错误,例如:

import org.apache.poi.ss.usermodel.*;

有什么想法吗? ?

I am referencing the version 3.7 of the Apache POI and I am getting a "cannot be resolved" error when I do:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

Other import statements that reference POI DO NOT give me errors, such as:

import org.apache.poi.ss.usermodel.*;

Any ideas??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

夕嗳→ 2024-11-11 14:18:55

首先,您需要在 pom.xml 中添加以下依赖项:

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

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

注意: 如果您的项目仍然找不到依赖项,请在 module-info.java 中添加以下行:

requires poi.ooxml;

First you need to add the following dependencies in your pom.xml:

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

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

NOTE: If your project still cannot find the dependecy, add the following line in your module-info.java:

requires poi.ooxml;
半寸时光 2024-11-11 14:18:54

你没有描述环境,无论如何,你应该下载apache poi库。如果您使用的是 eclipse,请右键单击根项目,然后在属性和 java 构建路径中添加外部 jar 并在项目中导入这些库:

xmlbeans-2.6.0; poi-ooxml-schemas- ... ; poi-ooxml-...; poi-...;

You did not described the environment, anyway, you should download apache poi libraries. If you are using eclipse , right click on your root project , so properties and in java build path add external jar and import in your project those libraries :

xmlbeans-2.6.0 ; poi-ooxml-schemas- ... ; poi-ooxml- ... ; poi- .... ;

趁年轻赶紧闹 2024-11-11 14:18:54

我的实现需要以下文件:

  • poi-ooxml-schemas-3.14.20160307.jar
  • commons-codec-1.10.jar (这位于您的 zip 文件的“lib”文件夹中)
    从apache获取)
  • curvesapi-1.03.jar(在“ooxml-lib”文件夹中)
  • poi-3.14-20160307.jar
  • poi-ooxml-3.14-20160307.jar
  • xmlbeans-2.6.0.jar(在“ooxml-lib”文件夹中)

(虽然说实话,我并不完全确定它们都是必要的......)这有点令人困惑,因为它们是这样包装的。我需要将它们手动放置在我自己的“lib”文件夹中,然后添加引用...

Maven 似乎总是下载比我需要的更多的东西,所以我总是手动放置 libaries/dll 和类似的东西。

I needed the following files for my implementation:

  • poi-ooxml-schemas-3.14.20160307.jar
  • commons-codec-1.10.jar (this was in "lib" folder of the zip file you
    get from apache)
  • curvesapi-1.03.jar (in "ooxml-lib" folder)
  • poi-3.14-20160307.jar
  • poi-ooxml-3.14-20160307.jar
  • xmlbeans-2.6.0.jar (in "ooxml-lib" folder)

(though honestly, I'm not completely sure they are all necessary...) It's a little confusing because they are packaged that way. I needed to place them manually in my own "lib" folder and then add the references...

Maven always seems to download more than I need, so I always place libaries/dlls and things like that manually.

悲凉≈ 2024-11-11 14:18:52

如果您使用 Maven:

添加 poi 和 poi-ooxml 依赖项以使其正常工作:)

<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>${poi.version}</version>
</dependency>
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi-ooxml</artifactId>
  <version>${poi-ooxml.version}</version>
</dependency>

If you use Maven:

Add the poi and the poi-ooxml dependency to make it work :)

<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi</artifactId>
  <version>${poi.version}</version>
</dependency>
<dependency>
  <groupId>org.apache.poi</groupId>
  <artifactId>poi-ooxml</artifactId>
  <version>${poi-ooxml.version}</version>
</dependency>
冬天的雪花 2024-11-11 14:18:51

在尝试了多种方法之后,真正有效的是:
1.手动下载“poi”和“poi-ooxml”
2.将这些 d/w jar 添加到“Maven 依赖项”中

After trying multiple things,what really worked was:
1. downloading "poi" and "poi-ooxml" manually
2.Adding these d/w jars into "Maven Dependencies"

送君千里 2024-11-11 14:18:50

我也遇到了同样的问题,所以我挖了poi-3.17.jar文件,里面没有xssf包。

然后我浏览了其他文件,发现 xssf int poi-ooxml-3.17.jar

所以看来解决方案是添加

poi-ooxml-3.17.jar

到您的项目中,因为这似乎使它工作(至少对我来说)

I had the same problem, so I dug through the poi-3.17.jar file and there was no xssf package inside.

I then went through the other files and found xssf int the poi-ooxml-3.17.jar

So it seems the solutions is to add

poi-ooxml-3.17.jar

to your project, as that seems to make it work (for me at least)

野却迷人 2024-11-11 14:18:49

2021 年 11 月 6 日实际情况:

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

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

Actual for 06.11.2021 days:

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

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.1.0</version>
</dependency>
八巷 2024-11-11 14:18:49

1)从 POI 文件夹导入所有 JAR
2)从POI文件夹的子目录ooxml文件夹导入所有JARS
3)从 POI 文件夹的子目录 lib 文件夹导入所有 JARS

String fileName = "C:/File raw.xlsx";
File file = new File(fileName);
FileInputStream fileInputStream;
Workbook workbook = null;
Sheet sheet;
Iterator<Row> rowIterator;
try {
        fileInputStream = new FileInputStream(file);
        String fileExtension = fileName.substring(fileName.indexOf("."));
        System.out.println(fileExtension);
        if(fileExtension.equals(".xls")){
        workbook  = new HSSFWorkbook(new POIFSFileSystem(fileInputStream));
        }
        else if(fileExtension.equals(".xlsx")){
        workbook  = new XSSFWorkbook(fileInputStream);
        }
        else {
        System.out.println("Wrong File Type");
        } 
        FormulaEvaluator evaluator workbook.getCreationHelper().createFormulaEvaluator();
        sheet = workbook.getSheetAt(0);
        rowIterator = sheet.iterator();
        while(rowIterator.hasNext()){
        Row row = rowIterator.next();
        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()){
        Cell cell = cellIterator.next();
        //Check the cell type after evaluating formulae
       //If it is formula cell, it will be evaluated otherwise no change will happen
        switch (evaluator.evaluateInCell(cell).getCellType()){
        case Cell.CELL_TYPE_NUMERIC:
        System.out.print(cell.getNumericCellValue() + " ");
        break;
        case Cell.CELL_TYPE_STRING:
        System.out.print(cell.getStringCellValue() + " ");
        break;
        case Cell.CELL_TYPE_FORMULA:
        Not again
        break;
        case Cell.CELL_TYPE_BLANK:
        break;
        }
}
 System.out.println("\n");
}
//System.out.println(sheet);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}​

1) imported all the JARS from POI folder
2) Imported all the JARS from ooxml folder which a subdirectory of POI folder
3) Imported all the JARS from lib folder which is a subdirectory of POI folder

String fileName = "C:/File raw.xlsx";
File file = new File(fileName);
FileInputStream fileInputStream;
Workbook workbook = null;
Sheet sheet;
Iterator<Row> rowIterator;
try {
        fileInputStream = new FileInputStream(file);
        String fileExtension = fileName.substring(fileName.indexOf("."));
        System.out.println(fileExtension);
        if(fileExtension.equals(".xls")){
        workbook  = new HSSFWorkbook(new POIFSFileSystem(fileInputStream));
        }
        else if(fileExtension.equals(".xlsx")){
        workbook  = new XSSFWorkbook(fileInputStream);
        }
        else {
        System.out.println("Wrong File Type");
        } 
        FormulaEvaluator evaluator workbook.getCreationHelper().createFormulaEvaluator();
        sheet = workbook.getSheetAt(0);
        rowIterator = sheet.iterator();
        while(rowIterator.hasNext()){
        Row row = rowIterator.next();
        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()){
        Cell cell = cellIterator.next();
        //Check the cell type after evaluating formulae
       //If it is formula cell, it will be evaluated otherwise no change will happen
        switch (evaluator.evaluateInCell(cell).getCellType()){
        case Cell.CELL_TYPE_NUMERIC:
        System.out.print(cell.getNumericCellValue() + " ");
        break;
        case Cell.CELL_TYPE_STRING:
        System.out.print(cell.getStringCellValue() + " ");
        break;
        case Cell.CELL_TYPE_FORMULA:
        Not again
        break;
        case Cell.CELL_TYPE_BLANK:
        break;
        }
}
 System.out.println("\n");
}
//System.out.println(sheet);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}​
腻橙味 2024-11-11 14:18:46

问题:导入“org.apache.poi.xssf.usermodel.XSSFWorkbook”类时,在 Eclipse 中显示错误。

解决方案:使用此maven依赖项来解决此问题:

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

-Hari Krishna Neela

Problem: While importing the " org.apache.poi.xssf.usermodel.XSSFWorkbook"class showing an error in eclipse.

Solution: Use This maven dependency to resolve this problem:

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

-Hari Krishna Neela

不爱素颜 2024-11-11 14:18:43

我找到了解决方案

你们需要牢记一些要点。

  1. 有两种不同的依赖关系,一种是 (poi) &其他依赖项是 (poi-
    ooxml
    ),但请确保您必须在代码中使用 poi-ooxml 依赖项。

  2. 只需在 pom.xml 中添加以下依赖项即可保存它。

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

3.保存pom.xml后,您需要尝试一些小事情,使用
(.) 操作员将尝试导入/获取它 &最终不会看到任何错误
因为现在它已经将那个东西导入到你的包中了。

示例代码以更好地理解!

package ReadFile;// package   
import org.apache.poi.xssf.usermodel.XSSFWorkbook;  // automatically added to your code after importing
public class Test          
{  
public static void Hello() // Method  
{  
XSSFWorkbook workbook = new XSSFWorkbook();   
}  
}

我尽力为您提供解决方案,如果您在这里遇到任何问题评论,我会尝试
来解决它。

继续学习伙计们!

I Got the Solution Guys

You need to keep some points in your mind .

  1. There are two different dependency one is (poi) & other dependency is (poi-
    ooxml
    ) but make sure you must use poi-ooxml dependency in your code.

  2. Just Add the following dependency in pom.xml & Save it.

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

3 .After you have saved the pom.xml then you need to try a small thing ,Use
(.) operator will try to import/fetch it & finally will not see any sort of error
because now it has imported that thing in your package.

Sample Code to Understand Better !!

package ReadFile;// package   
import org.apache.poi.xssf.usermodel.XSSFWorkbook;  // automatically added to your code after importing
public class Test          
{  
public static void Hello() // Method  
{  
XSSFWorkbook workbook = new XSSFWorkbook();   
}  
}

I tried my best to give you the solution , If you face any issue comment here i will try
to solve it .

Keep Learning Guys !!

情话难免假 2024-11-11 14:18:38

如果您使用 Maven:

poi => artifactId 中的 poi-ooxml

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

If you use Maven:

poi => poi-ooxml in artifactId

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.12</version>
    </dependency>
旧情勿念 2024-11-11 14:17:57

我在应用程序“build.gradle”中添加了以下内容

implementation 'org.apache.poi:poi:4.0.0'
implementation 'org.apache.poi:poi-ooxml:4.0.0'

I added below contents in app "build.gradle"

implementation 'org.apache.poi:poi:4.0.0'
implementation 'org.apache.poi:poi-ooxml:4.0.0'
撕心裂肺的伤痛 2024-11-11 14:17:40

OOXML 文件格式的类(例如 .xlsx 的 XSSF)位于不同的 Jar 文件中。您需要在项目中包含 poi-ooxml jar 及其依赖项

您可以在 POI 网站 此处

您可能想要做的是下载 3.11 二进制包,获取 poi-ooxml jar,以及 ooxml-lib 目录中的依赖项。将这些导入到您的项目中,您就会被排序。

或者,如果您使用 Maven,则可以查看此处以获取您的工件列表你想要依赖,但它希望是这样的:

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

poi-ooxml maven 依赖项将自动为你引入主 POI jar 和依赖项。如果您想使用非电子表格格式,您还需要依赖 poi-scratchpad 工件,详见 POI 组件页面

The classes for the OOXML file formats (such as XSSF for .xlsx) are in a different Jar file. You need to include the poi-ooxml jar in your project, along with the dependencies for it

You can get a list of all the components and their dependencies on the POI website here.

What you probably want to do is download the 3.11 binary package, grab the poi-ooxml jar from it, and the dependencies in the ooxml-lib directory. Import these into your project and you'll be sorted.

Alternately, if you use Maven, you can see here for the list of the artificats you'll want to depend on, but it'd want to be something like:

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

The poi-ooxml maven dependency will pull in the main POI jar and the dependencies for you automatically. If you want to work with the non-spreadsheet formats, you'd also want to depend on the poi-scratchpad artifact too, as detailed on the POI components page

无人问我粥可暖 2024-11-11 14:17:29

为了使 OOXML 工作,您需要 POI-OOXML jar,它与 POI jar 分开打包。

从以下位置下载 POI-OOXML jar -

http://repo1.maven.org/maven2/org/apache/poi/poi-ooxml/3.11/poi-ooxml-3.11.jar

对于 Maven2 添加以下依赖项 -

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

For OOXML to work you need the POI-OOXML jar which is separately packaged from the POI jar.

Download the POI-OOXML jar from the following location -

http://repo1.maven.org/maven2/org/apache/poi/poi-ooxml/3.11/poi-ooxml-3.11.jar

For Maven2 add the below dependency -

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.11</version>
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文