从 Excel 工作表中获取值作为 PHP 中的日期


Get the value from Excel Sheet as Date in PHP

我使用 PhpExcelReader--
包括"excel_reader.php"; 包括类

// creates an object instance of the class, and read the excel file data
$excel = new PhpExcelReader;

数据读取和函数调用--

$excel->read('test.xls');
sheetData($excel->sheets[0]);

功能代码--

function sheetData($sheet) 
{
    while($x <= $sheet['numRows']) 
    {
        if(@$sheet['cells'][$x][1])
        {
            while($y <= $sheet['numCols']) 
            {
                $cell = isset($sheet['cells'][$x][$y]) ? $sheet['cells'][$x][$y] : '';
                echo $cell = @date($cell)."<br/>";
            }
         }
     }
}

它只显示像 36400
这样的数字在那之后我尝试了

echo $cell = @date("Y-m-d",$cell)."<br/>";

但它显示默认值,如 1970-01-01
但我的数据 2004-05-12

Excel 中的"日期"字段是"自 1900 年 1 月 0 日以来的天数",而 PHP 中的时间是"自 1970 年 1 月 1 日 00:00 以来的秒数"。从那里转换应该很容易。

使用此处详述的函数 https://phpexcel.codeplex.com/discussions/219301

$PHPDate = PHPExcel_Shared_Date::ExcelToPHP($cell);
echo date("Y-m-d", $PHPDate);