且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Apache POI HSSFListener 如何识别日期类型

更新时间:2023-11-29 13:08:28

Excel 文件格式将所有日期存储为具有特殊格式规则的数字.并不是 HSSF 正在转换它,您得到的正是 Excel 存储在文件中的内容!

如果你想要 .xls 文件的 HSSF 事件处理的好例子,我建议你看看 来自 Apache POI 的 XLS2CSVmra来自Apache Tika的ExcelExtractor>

两者都显示了许多您想要做的常见事情,包括检测日期单元格并适当地格式化它们以进行显示

Due to millions of records to handle, I have to handle SAX parsing using the technique given here. http://poi.apache.org/spreadsheet/how-to.html#event_api. However Date type is convered to Number. How to distinguish between Date and Number when using HSSFListener?

The Excel file formats store all dates as numbers with special formatting rules. It's not that HSSF is converting it, you're getting exactly what Excel stores in the file!

If you want good examples of HSSF Event processing for .xls files, I would suggest you take a look at XLS2CSVmra from Apache POI and ExcelExtractor from Apache Tika

Both show a number of common things you'll want to do, including detecting Date cells and formatting them appropriately for display