Phpspreadsheet - Time cell retrieved as float

后端 未结 2 459
说谎
说谎 2021-01-21 08:47

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

B

相关标签:
2条回答
  • 2021-01-21 09:08

    Formart the data before you read it.

    For example:

    cell data 2020/10/13 19:00:00

    Access directly will get 44117.791666667

    $sheet->toArray();
    

    Format before access will get 2020-10-13 19:00:00

    $row_num = $sheet->getHighestDataRow();
    $sheet->getStyle("H1:H$row_num")->applyFromArray(array("numberFormat"=>array("formatCode"=>'yyyy-mm-dd hh:mm:ss'))); // H is the datatime row
    $sheet->toArray();
    
    0 讨论(0)
  • 2021-01-21 09:15

    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.

    0 讨论(0)
提交回复
热议问题