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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度