HH:MM:SS xls reading using Apache POI

安稳与你 提交于 2019-12-08 05:23:21

问题


Please help me how to read an xls which file using Apache POI having cell value in the format HH:MM:SS.

I am able to read cell value if time stamp in xls cell less than or equal 24 hours. (e.g. 23:30:30).

Now my requirement is to read the same cell value even greater than 24 hours (e.g. 55:34:34) and store it in the database.


回答1:


Dates and times in Excel are stored as floating point numbers. Dates are days since 1900 (a date of 1 is 01/01/1900), and times are fractions of a day (so 0.5 is 12 hours).

Depending on what format you need the value to be in before you put it in a database, then you might just want to take the numeric value and multiple by 24 to get the hours and fractional hours, eg:

double time = cell.getNumericCellValue() * 24;
int hours = (int)time;
int minutes = (time - hours) * 60;

Alternately, if you want a string, then the DataFormatter class will happily format a value of 1.5 as HH:MM to 36:00



来源:https://stackoverflow.com/questions/4683828/hhmmss-xls-reading-using-apache-poi

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