可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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??
回答1:
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>
回答2:
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
回答3:
If you use Maven:
poi => poi-ooxml in artifactId
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
回答4:
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'
回答5:
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
回答6:
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();
}
回答7:
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)
回答8:
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- .... ;
回答9:
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.
回答10:
After trying multiple things,what really worked was:
1. downloading "poi" and "poi-ooxml" manually
2.Adding these d/w jars into "Maven Dependencies"