我引用了Apache POI的3.7版本,我得到一個 「無法解析」 的錯誤,當我做:不能在Apache中導入XSSF POI
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
其他import語句引用POI DO NOT給我的錯誤,如:
import org.apache.poi.ss.usermodel.*;
任何想法?
我引用了Apache POI的3.7版本,我得到一個 「無法解析」 的錯誤,當我做:不能在Apache中導入XSSF POI
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
其他import語句引用POI DO NOT給我的錯誤,如:
import org.apache.poi.ss.usermodel.*;
任何想法?
要使OOXML正常工作,您需要POI-OOXML jar,它是從POI jar中分別打包的。
下載從以下位置的POI-OOXML罐子 -
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爲.xlsx)位於不同的Jar文件中。您需要在您的項目中包含poi-ooxml jar以及它的依賴關係
您可以在POI網站here上獲得所有組件及其依賴關係的列表。
你可能想要做的就是下載3.11 binary package,從中獲取poi-ooxml
jar以及ooxml-lib
目錄中的依賴關係。將這些導入到您的項目中,然後您將進行排序。
另外,如果你使用Maven,你可以see here的artificats的名單,你會想要依靠,但它會想是這樣的:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
的POI,OOXML行家依賴關係將自動爲您提供主POI jar和依賴關係。如果你想與非電子表格格式,您還願意要取決於poi-scratchpad
神器也一樣,從POI文件夾的POI components page
這爲我工作,thx! – MemLeak 2012-09-21 06:56:42
1)進口的所有JAR文件的詳細 2)進口的所有的罐子從OOXML夾哪個POI文件夾的子目錄 3)進口所有從lib文件夾中的JAR這是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();
}
感謝,非常有用 – 2017-02-20 20:49:15
行不進口...你可以共享jar文件鏈接請 – Mariyappan 2017-09-19 07:20:06
的子目錄如果使用Maven:
POI => POI-OOXML在artifactId
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
</dependency>
我建議使用POI 3.12最終('3.12')而不是beta版 – Gagravarr 2015-05-12 12:48:47
您沒有描述環境,無論如何,你應該下載apache poi庫。如果您使用的是Eclipse,右鍵單擊您的根項目,那麼屬性和java構建路徑添加外部jar並在您的項目中導入這些庫:
xmlbeans-2.6.0; poi-ooxml-schemas- ...; poi-ooxml- ...; poi ....;
我需要爲我執行下列文件:
(不過說實話,我不能完全肯定他們是所有必要的...)這是一個有點混亂,因爲他們是封裝的辦法。我需要將它們手動放置在我自己的「lib」文件夾中,然後添加參考文件...
Maven似乎總是下載比我需要的更多,所以我總是手動放置libaries/dll和類似的東西。
Apache POI [提供了一個方便的頁面,解釋什麼罐子是什麼](http://poi.apache.org/overview.html#components)需要,你需要的一切都在二進制下載,所以它不必混亂或神祕! – Gagravarr 2016-03-11 11:08:15
如果您要使用Maven,該頁面非常方便,但我更願意手動添加依賴項。該頁面不會單獨列出所有內容。其中一些在構建時並不明顯,但您可以通過在運行時檢查異常來找到它們。我的實現將XLS和XLSX文件導入到jtable中。上述似乎是所需要的。 – pcalkins 2016-03-24 22:49:56
這裏列出的所有東西都在二進制下載!無論組件需要什麼,以及罐子需要什麼依賴關係 – Gagravarr 2016-03-24 23:30:37
問題:導入在eclipse中顯示錯誤的「org.apache.poi.xssf.usermodel.XSSFWorkbook」類。
解決方案:使用該maven的依賴關係來解決這一問題:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
-Hari克里希納尼拉
這正是我需要的。對於我(版本3.11),我只需要添加一個附加的jar:poit-ooxml-3.11-20141221.jar。我沒有意識到他們之間沒有任何聯繫。謝謝你的回答Pushkar +1。 – 2015-05-06 18:33:04
謝謝@Pushkar – Binay 2015-06-24 07:32:38