java - poi-ooxml-schemas-3.14 JAR 中缺少 STSheetViewType 类

标签 java eclipse excel jar apache-poi

目前我正在尝试实现 this question: 的答案中给出的代码

CTSheetView view =  sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0);
view.setView(STSheetViewType.PAGE_LAYOUT);

但是 poi-ooxml-schemas(版本 3.14)JAR 文件不包含 STSheetViewType 类。我深入研究了 poi-ooxml-schemas JAR 文件(使用 7ZIP),发现类文件 STSheetViewType$Enum.class 存在于路径中:

org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType$Enum.class

但是(如果我没记错的话)“$”表示内部/嵌套类,这意味着 STSheetViewType 枚举封装在另一个类中。我检查了旧版本 poi-ooxml-schemas(版本 1.1)中 STSheetViewType 类的文档 here并发现类 STSheetViewType 包含一个内部 Enum STSheetViewType.Enum。

我从 Eclipse 中收到的错误似乎也证实了这一点。使用上面显示的代码时出现这些错误:

“STSheetViewType 无法解析为变量”

“无法解析类型 org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetViewType。它是从所需的 .class 文件间接引用的”

这进一步让我相信 STSheetViewType.Enum 缺少其父 STSheetViewType 类文件。但为什么?我检查了新版本 poi-ooxml-schemas-3.14 的文档,发现更改日志中没有提及 STSheetViewType。我已经多次下载 POI 的二进制 zip 文件,以确保我的下载没有错误,我什至下载了源代码并尝试构建 JAR,但每次都缺少类文件。

我发现另一个 Jar 文件中包含一个看似具有相同功能的 STSheetViewType 类 here但我似乎无法正确导入该类。这样的事有可能吗?或者类文件必须与 poi-ooxml-schemas-3.14 JAR 文件一起提供吗?

最终我想了解如何使上述代码与当前版本的 poi-ooxml-schemas-3.14 JAR 兼容。任何有关此的信息或见解将不胜感激。

最佳答案

正如 @AxelRichter 和常见问题解答所指出的,Apache POI 3.14 及更高版本使用 ooxml-schemas-1.3.jar 中的类子集。您需要获取该 jar 文件并将其包含在类路径中,而不是 poi-ooxml-schemas-3.14.jar。 POI 仅提供它所需的 ooxml 模式类。当您开始在自己的代码中直接调用 ooxml 架构类时,您很可能必须获取包含所有 ooxml 架构类的完整 jar 以避免出现此类问题。您可以从mavencentral获取jar:

http://central.maven.org/maven2/org/apache/poi/ooxml-schemas/1.3/

另请参阅常见问题解答条目 http://poi.apache.org/faq.html#faq-N10025

关于java - poi-ooxml-schemas-3.14 JAR 中缺少 STSheetViewType 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38403554/

相关文章:

java - 找不到依赖项 [CountryRepository] ​​: expected at least 1 bean which qualifies as autowire candidate 的合格 bean

java - 数据集中的行数问题

excel - VBA-删除工作表 1 中的整行

c# - 在C#中将excel文件转换为jpg

java - 拦截 WiFi 请求

java - Spring Boot从1.5迁移到2.1, hibernate 错误

Android Eclipse Lint API 检查

c++ - 体系结构 x86_64 : Eclipse 的重复符号

eclipse - 取决于 Eclipse 中 tools.jar (Sun JDK) 的 com.sun.javadoc

java - 读取 .xls 和 .xlsx 格式的 excel 文件时出现 jxl.read.biff.BiffException 异常