无法在Apache POI中导入XSSF

时间:2021-03-13 20:23:46

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

我正在引用Apache POI的3.7版本,当我这样做时,我收到“无法解决”的错误:

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

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

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

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

Any ideas??

有任何想法吗??

8 个解决方案

#1


165  

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

要使OOXML正常工作,您需要POI-OOXML jar,它与POI jar分开包装。

Download the POI-OOXML jar from the following location -

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

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

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

For Maven2 add the below dependency -

对于Maven2添加以下依赖项 -

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

#2


28  

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

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

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

您可以在此处获取POI网站上所有组件及其依赖项的列表。

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.

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

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:

或者,如果您使用Maven,您可以在此处查看您想要依赖的artificat列表,但它希望是这样的:

<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

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

#3


7  

If you use Maven:

如果你使用Maven:

poi => poi-ooxml in artifactId

poi => artifactId中的poi-ooxml

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

#4


5  

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

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

Solution: Use This maven dependency to resolve this problem:

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

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

-Hari Krishna Neela

-Hari Krishna Neela

#5


2  

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

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

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();
}​

#6


0  

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 :

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

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

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

#7


0  

I needed the following files for my implementation:

我需要以下文件来实现:

  • poi-ooxml-schemas-3.14.20160307.jar
  • POI-OOXML-架构 - 3.14.20160307.jar
  • commons-codec-1.10.jar (this was in "lib" folder of the zip file you get from apache)
  • commons-codec-1.10.jar(这是你从apache获得的zip文件的“lib”文件夹)
  • curvesapi-1.03.jar (in "ooxml-lib" folder)
  • curvesapi-1.03.jar(在“ooxml-lib”文件夹中)
  • poi-3.14-20160307.jar
  • POI-3.14-20160307.jar
  • poi-ooxml-3.14-20160307.jar
  • POI-OOXML-3.14-20160307.jar
  • xmlbeans-2.6.0.jar (in "ooxml-lib" folder)
  • xmlbeans-2.6.0.jar(在“ooxml-lib”文件夹中)

(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...

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

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

Maven似乎总是下载超过我需要的内容,所以我总是手动放置libaries / dll和类似的东西。

#8


0  

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

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

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

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

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)

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

#1


165  

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

要使OOXML正常工作,您需要POI-OOXML jar,它与POI jar分开包装。

Download the POI-OOXML jar from the following location -

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

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

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

For Maven2 add the below dependency -

对于Maven2添加以下依赖项 -

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

#2


28  

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

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

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

您可以在此处获取POI网站上所有组件及其依赖项的列表。

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.

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

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:

或者,如果您使用Maven,您可以在此处查看您想要依赖的artificat列表,但它希望是这样的:

<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

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

#3


7  

If you use Maven:

如果你使用Maven:

poi => poi-ooxml in artifactId

poi => artifactId中的poi-ooxml

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

#4


5  

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

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

Solution: Use This maven dependency to resolve this problem:

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

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

-Hari Krishna Neela

-Hari Krishna Neela

#5


2  

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

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

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();
}​

#6


0  

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 :

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

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

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

#7


0  

I needed the following files for my implementation:

我需要以下文件来实现:

  • poi-ooxml-schemas-3.14.20160307.jar
  • POI-OOXML-架构 - 3.14.20160307.jar
  • commons-codec-1.10.jar (this was in "lib" folder of the zip file you get from apache)
  • commons-codec-1.10.jar(这是你从apache获得的zip文件的“lib”文件夹)
  • curvesapi-1.03.jar (in "ooxml-lib" folder)
  • curvesapi-1.03.jar(在“ooxml-lib”文件夹中)
  • poi-3.14-20160307.jar
  • POI-3.14-20160307.jar
  • poi-ooxml-3.14-20160307.jar
  • POI-OOXML-3.14-20160307.jar
  • xmlbeans-2.6.0.jar (in "ooxml-lib" folder)
  • xmlbeans-2.6.0.jar(在“ooxml-lib”文件夹中)

(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...

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

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

Maven似乎总是下载超过我需要的内容,所以我总是手动放置libaries / dll和类似的东西。

#8


0  

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

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

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

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

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)

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