Apache POI에서 XSSF를 가져올 수 없습니다
Apache POI 버전 3.7을 참조하고 있는데 "해결할 수 없음"오류가 발생합니다.
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
POI를 참조하는 다른 import 문 은 다음과 같은 오류를 발생 시키지 않습니다 .
import org.apache.poi.ss.usermodel.*;
어떤 아이디어 ??
OOXML이 작동하려면 POI jar과 별도로 패키지 된 POI-OOXML 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>
OOXML 파일 형식 (예 : XSSF for .xlsx)의 클래스는 다른 Jar 파일에 있습니다. 프로젝트에 poi-ooxml jar을 종속성과 함께 포함시켜야합니다.
POI 웹 사이트 에서 모든 구성 요소 및 해당 종속성 목록을 얻을 수 있습니다 .
아마도 원하는 것은 3.11 바이너리 패키지를 다운로드하고 , poi-ooxmljar 파일과 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 구성 요소 페이지 에 설명 된대로 아티팩트도 의존하고 싶습니다 .
Maven을 사용하는 경우 :
artifactId의 poi => poi-ooxml
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
문제점 : "org.apache.poi.xssf.usermodel.XSSFWorkbook"클래스를 가져 오는 중에 오류가 발생했습니다.
솔루션 :이 maven 종속성을 사용하여이 문제를 해결하십시오.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
하리 크리슈나 넬라
앱 "build.gradle"에 아래 내용을 추가했습니다.
implementation 'org.apache.poi:poi:4.0.0'
implementation 'org.apache.poi:poi-ooxml:4.0.0'
1) POI 폴더에서 모든 JARS 가져 오기 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();
}
나는 같은 문제가 있었으므로 poi-3.17.jar 파일을 파고 xssf 패키지가 없었습니다.
그런 다음 다른 파일을 살펴보고 pos-ooxml-3.17.jar에서 xssf를 찾았습니다.
솔루션이 추가하는 것 같습니다.
poi-ooxml-3.17.jar
그것이 프로젝트를 작동시키는 것처럼 보이기 때문에 (적어도 나를 위해)
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- .... ;
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.
After trying multiple things,what really worked was: 1. downloading "poi" and "poi-ooxml" manually 2.Adding these d/w jars into "Maven Dependencies"
참고URL : https://stackoverflow.com/questions/5878341/cannot-import-xssf-in-apache-poi
'programing tip' 카테고리의 다른 글
| PHP 공지를 끄려면 어떻게합니까? (0) | 2020.07.26 |
|---|---|
| tsconfig.json 파일을 어떻게 생성합니까? (0) | 2020.07.25 |
| Java 열거 형에서 valueof () 및 toString () 재정의 (0) | 2020.07.25 |
| Anaconda에서 이전 패키지로 되돌리려면 어떻게합니까? (0) | 2020.07.25 |
| Spring MVC-Rest Controller에서 간단한 문자열을 JSON으로 반환하는 방법 (0) | 2020.07.25 |