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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。