简体   繁体   English

Apache POI HSSF/XSSF 到 XLS/XLSX 的映射

[英]Mapping of Apache POI HSSF/XSSF to XLS/XLSX

Apache POI 4.x here. Apache POI 4.x 在这里。 I see there are two types of Workbook implementations:我看到有两种类型的Workbook实现:

  • HSSF Workbook HSSF 工作簿
  • XSSF Workbook XSSF 工作簿

I need to write a Java 8 app that reads Excel sheets with either " .xls " (XLS) or " .xlsx " (XLSX) extensions.我需要编写一个 Java 8 应用程序,它可以读取带有“ .xls ”(XLS)或“ .xlsx ”(XLSX)扩展名的 Excel 表。 Meaning, Excel files that were saved in the "old" (pre 2003) format, or the newer one.意思是,Excel 文件以“旧”(2003 年之前)格式或更新的格式保存。

Is it safe to assume I use HSSF for XLS files, and XSSF for XLSX files?假设我对 XLS 文件使用 HSSF,对 XLSX 文件使用 XSSF 是否安全? Or is the mapping logic a little bit more complicated there?还是那里的映射逻辑有点复杂? This answer seems to indicate I'm correct, but that doesn't leave me feeling totally sure that I understand the mapping and "when to use" logic of HSSF vs XSSF.这个答案似乎表明我是正确的,但这并不能让我完全确定我理解 HSSF 与 XSSF 的映射和“何时使用”逻辑。

I've scoured the POI documentation but can't find a clear answer for the life of me.我已经搜索了 POI 文档,但无法为我的生活找到明确的答案。

HSSF ( org.apache.poi.hssf.usermodel package) is for XLS files format HSSF( org.apache.poi.hssf.usermodel包)用于 XLS 文件格式

XSSF ( org.apache.poi.xssf.usermodel package) is for XLSX files format (newer one) XSSF( org.apache.poi.xssf.usermodel包)适用于 XLSX 文件格式(较新的一种)

Model classes from both packages (xssf and hssf) implements common interfaces from org.apache.poi.ss.usermodel package.来自两个包(xssf 和 hssf)的 Model 类实现了来自org.apache.poi.ss.usermodel ZEFE90A8E604A7C840E88ZD03A67F6B78 的通用接口。 So, you potentially can write a code using ss package and it will work with abstractions over xssf or hssf.因此,您可能可以使用ss package 编写代码,它将与 xssf 或 hssf 上的抽象一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM