Mapping of Apache POI HSSF/XSSF to XLS/XLSX

你说的曾经没有我的故事 提交于 2021-02-16 20:33:15

问题


Apache POI 4.x here. I see there are two types of Workbook implementations:

  • HSSF Workbook
  • XSSF Workbook

I need to write a Java 8 app that reads Excel sheets with either ".xls" (XLS) or ".xlsx" (XLSX) extensions. Meaning, Excel files that were saved in the "old" (pre 2003) format, or the newer one.

Is it safe to assume I use HSSF for XLS files, and XSSF for XLSX files? 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.

I've scoured the POI documentation but can't find a clear answer for the life of me.


回答1:


HSSF (org.apache.poi.hssf.usermodel package) is for XLS files format

XSSF (org.apache.poi.xssf.usermodel package) is for XLSX files format (newer one)

Model classes from both packages (xssf and hssf) implements common interfaces from org.apache.poi.ss.usermodel package. So, you potentially can write a code using ss package and it will work with abstractions over xssf or hssf.



来源:https://stackoverflow.com/questions/58883341/mapping-of-apache-poi-hssf-xssf-to-xls-xlsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!