POI 3.9 Excel 읽기
private Map<String, Object> readExcel(File excel) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("success", false);
FileInputStream fis = null;
Workbook wb = null;
int saveCount = 0;
try {
try {
fis = new FileInputStream(excel);
wb = WorkbookFactory.create(fis);
for (int s = 0; s < wb.getNumberOfSheets(); s++) {
Sheet sheet = wb.getSheetAt(s);
int rowNum = sheet.getPhysicalNumberOfRows();
if (rowNum < 1) {
result.put("msg", " ");
return result;
}
for (int r = 0; r < rowNum; r++) {
Row row = sheet.getRow(r);
if (row == null) {
continue;
}
int cells = row.getPhysicalNumberOfCells();
for (int c = 0; c < cells; c++) {
Cell cell = row.getCell(c);
String value = null;
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
value = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
value = cell.getNumericCellValue() + "";
if (value.endsWith(".0")) {
value = value.substring(0, value.length() - 2);
}
break;
case HSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
default:
}
System.out.println(value);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
result.put("msg", " [" + saveCount + "] ");
result.put("success", true);
return result;
}
질문:
"java.lang.NoClassDefFoundError: org/openxmlformats/schemas/*something*"
org.openxmlformats.schemas.wordprocessingml.x2006
홈페이지에 설명이 있어요.
I'm using the poi-ooxml-schemas jar, but my code is failing with "java.lang.NoClassDefFoundError: org/openxmlformats/schemas/*something*"
To use the new OOXML file formats, POI requires a jar containing the file format XSDs, as compiled by XMLBeans. These XSDs, once compiled into Java classes, live in the org.openxmlformats.schemas namespace.
There are two jar files available, as described in the components overview section. The full jar of all of the schemas is ooxml-schemas-1.1.jar, and it is currently around 15mb. The smaller poi-ooxml-schemas jar is only about 4mb. This latter jar file only contains the typically used parts though.
Many users choose to use the smaller poi-ooxml-schemas jar to save space. However, the poi-ooxml-schemas jar only contains the XSDs and classes that are typically used, as identified by the unit tests. Every so often, you may try to use part of the file format which isn't included in the minimal poi-ooxml-schemas jar. In this case, you should switch to the full ooxml-schemas-1.1.jar. Longer term, you may also wish to submit a new unit test which uses the extra parts of the XSDs, so that a future poi-ooxml-schemas jar will include them.
There are a number of ways to get the full ooxml-schemas-1.1.jar. If you are a maven user, see the the components overview section for the artifact details to have maven download it for you. If you download the source release of POI, and/or checkout the source code from subversion, then you can run the ant task "compile-ooxml-xsds" to have the OOXML schemas downloaded and compiled for you (This will also give you the XMLBeans generated source code, in case you wish to look at this). Finally, you can download the jar by hand from the POI Maven Repository.
Note that for POI 3.5 and 3.6, the full ooxml schemas jar was named ooxml-schemas-1.0.jar. For POI 3.7, the filename was bumped to ooxml-schemas-1.1.jar when generics support was added. You can use ooxml-schemas-1.1.jar with POI 3.5 and 3.6 if you wish, but POI 3.7 won't wokr with ooxml-schemas-1.0.jar (it needs thew newer one).
간단하게 말하면 공식 lib 중의 Poi-ooxml-schemas-3.9-20121203은 수축된 버전으로 자주 사용하는 일부 종류만 제공한다.그래서 해결책은 ooxml-schemas를 가져오는 거예요. -1.1.jar 대신poi-ooxml-schemas-3.9-20121203.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
POI Excel 사용자 정의 날짜 형식 읽기 (인스턴스 코드)POI로 Excel 데이터 읽기: (버전 번호: POI3.7) 1. Excel 읽기 2, Excel 데이터 처리: Excel 저장 날짜, 시간은 모두 수치 형식으로 저장되며, 읽을 때 POI가 먼저 수치 유형인지 아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.