HH:MM:SS xls 使用 Apache POI 读取 [英] HH:MM:SS xls reading using Apache POI
问题描述
请帮助我如何使用具有 HH:MM:SS
格式的单元格值的 Apache POI 读取 xls
哪个文件.
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: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:SS xls 使用 Apache POI 读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!