dtcn30461 2013-10-16 12:39
浏览 113
已采纳

无法使用PHP中的Spreadsheet_Excel_Reader从电子表格中读取时间值

I am trying to import an excel file into my database in PHP. The file contains a column which has time values in the format H:MM. When I try to read this column, I get garbage values like 0.416666666667.

My code goes here :

    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('CP1252');             
    $data->setUTFEncoder('mb');
    $data->read($filePath);
    echo $data->sheets[0]['cells'][$i][$j];

Am I missing something? The value in the column is 10:00 but all I get is 0.416666666667.

Please help.

  • 写回答

2条回答 默认 最新

  • dongyuedaochen8415 2013-10-16 14:13
    关注

    The value in the MS Excel cell is a serialized timestamp, it's formatted as a human readable date/time by the format mask, which SER isn't particularly good at handling

    $time =  0.416666666667 * 86400;
    $hours = round($time / 3600);
    $minutes = round($time / 60) - ($hours * 60);
    $seconds = round($time) - ($hours * 3600) - ($minutes * 60);
    
    echo sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 请教一下c语言的代码里有一个地方不懂
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档