HH:MM:使用Apache POI SS XLS阅读 [英] HH:MM:SS xls reading using Apache POI
问题描述
请帮助我如何读 XLS
该文件中的格式使用Apache POI有单元格值 HH:MM:SS
。
Please help me how to read an xls
which file using Apache POI having cell value in the format HH:MM:SS
.
我能够读取单元格的值如果 XLS
细胞时间戳小于或等于24小时。 (例如 23时30分三十〇秒
)。
I am able to read cell value if time stamp in xls
cell less than or equal 24 hours. (e.g. 23:30:30
).
现在我的要求是读取相同的单元格的值甚至超过24小时(如 55:34:34
),并将其存储在数据库中。
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.
推荐答案
日期和时间在Excel中存储为浮点数字。日期是天自1900年以来(1日期是01/01/1900),并且时间是每天的分数(所以0.5是12小时)。
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).
根据您所需要的价值是什么格式,你把它放在一个数据库之前在,那么你可能只是想通过24取数值和多获得的时间和分数小时,如:
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;
另外,如果你想有一个字符串,则DataFormatter类会很乐意的1.5作为一个HH值格式:MM到36:00
Alternately, if you want a string, then the DataFormatter class will happily format a value of 1.5 as HH:MM to 36:00
这篇关于HH:MM:使用Apache POI SS XLS阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!