how to get date from excel using PHPExcel library

前端 未结 5 1207
故里飘歌
故里飘歌 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:49

    You can get the cell values as string (also the date values) this way:

    $sheet = $objPHPExcel->getActiveSheet();
    $lastRow = $sheet->getHighestRow();
    $lastColumn = $sheet->getHighestColumn();
    
    $rows = $sheet->rangetoArray('A2:'.$lastColumn . $lastRow, NULL, True, True, False);
    foreach ($rows as $row => $cols) {
        foreach($cols as $col => $cell) {
            echo trim($cell).'
    '; // Gives the value as string } }

提交回复
热议问题