本文介绍了Phpspreadsheet-以浮点数形式检索的时间单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有时间输入的excel文件.
I have an excel file which has a time input.
Mar 01, 2018 | Thursday | 8:00 AM | 5:00 PM
Mar 02, 2018 | Friday | 8:00 AM | 5:00 PM
但是,当我的代码尝试读取这些单元格时,输出将变为浮点型(例如,8:00 AM
变为0.33333333333333
).这是我的代码
But when my code tries to read those cells, the output becomes a float (for example 8:00 AM
becomes 0.33333333333333
). This is my code
$date = $sheet->getCell("A".$row)->getValue();
$time_in = $sheet->getCell("C".$row)->getValue();
$time_out = $sheet->getCell("D".$row)->getValue();
echo "date: ".$date. //Mar 01, 2018
" time_in: ".$time_in. //becomes 0.333333333333333
" time_out: ".$time_out; //becomes 0.708333333333333
如何在不使phpspreadsheet更改值的情况下原样输出?我尝试查看phpspreadsheet文档,但没有找到解决方案.
How can I make the output as is without the phpspreadsheet changing the value? I have tried looking at the phpspreadsheet documentation but I haven't found a solution.
推荐答案
非常感谢,我现在才找到答案.
Thankfully I have found the answer just now.
$in = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($time_in);
echo gmdate("g:i a", $in);
希望这对其他人可能有用.
Hopefully, this could be useful for others.
这篇关于Phpspreadsheet-以浮点数形式检索的时间单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!