1

我正在使用日期和时间单元格值,当日期值正常工作时,时间证明有点痛苦。

$value = $worksheet->getCell($cellPosition)->getValue();
$date = new \DateTime();
$date->setTimestamp(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($value));
echo '<td>' . $date->format('i:s') . '</td>' . PHP_EOL;

但是,在此示例中:$value是:0.375 而不是:09:00,因此格式化失败。

如何禁用此默认值格式?

4

1 回答 1

0

\PhpOffice\PhpSpreadsheet\Calculation\Functions::setReturnDateType($returnDateType)脚本可以通过调用该方法来更改用于返回日期值的数据类型。

作为$returnDateType使用常量RETURNDATE_PHP_OBJECT

然后通过访问 Excel 中的日期和时间函数返回给调用脚本的日期值将是PHP DateTime object

处理日期和时间值

于 2017-12-18T12:37:34.067 回答