how to get date from excel using PHPExcel library

前端 未结 5 1196
故里飘歌
故里飘歌 2020-12-02 17:00

I am trying to get Date from excel using PHPExcel. But I am not getting date, I am getting string value which is not seconds from 1970 .

Code I have tried is

<
5条回答
  •  情深已故
    2020-12-02 17:46

    In the new version of the library, PhpOffice, the function that handles this is excelToDateTimeObject so the new code format should be:

    $cell = $excel->getActiveSheet()->getCell('B' . $i);
    $InvDate= $cell->getValue();
    if (PhpOffice\PhpSpreadsheet\Shared\Date::isDateTime($cell)) {
         $InvDate = PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($InvDate); 
    }
    

提交回复
热议问题