我编写了简单的 groovy spock 测试用例来验证 Excel 工作表。在我的“然后”部分中,我有以下内容。
then:"Should return the excel work book"
workbook != null
workbook.getNumberOfSheets() == 3
def sheet = workbook.getSheetAt(1);
def row = sheet.getRow(4).getCell(0)
def cell = row.getCell(0);
cell.cellValue
println cell
我得到java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList
访问像 cell.cellValue
这样的单元格值时.
您能告诉我这里出了什么问题吗?
查看 jar poi-ooxml-schemas-3.14.jar,该类不可用。该类在 poi-ooxml-schemas-3.14.jar 中不可用,还是我们必须引用其他 jar?
另外,通过查看此链接 APACHE POI ,我知道我们需要完整的 jar,大小为 15 MB。我怎样才能用maven得到它?
最佳答案
如 this Apache POI FAQ Entry 中所述,poi-ooxml-schemas
jar 仅包含 OOXML 模式的最常见部分。如果您需要使用通用集之外的任何内容,则必须获取完整的 OOXML Schemas jar,当前为 ooxml-schemas-1.3.jar
如上所述in that FAQ和 POI Components page ,作为 Maven 用户,您可以使用如下依赖项来做到这一点:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.3</version>
</dependency>
关于java - Apache POI 测试用例失败,因为它找不到 CTExtensionList 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38581004/