且构网

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

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

更新时间:2023-11-29 13:03:40

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

如果您想要.xls文件的HSSF事件处理的好示例,我建议您看一下来自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