add support for dates with XLSX writer (fixes #797)

This adds support for writing DateTime and DateTimeImmutable values with
the XLSX writer. The dates are written using the date type (t="d") which
must then specify an ISO date as the value (as opposed to a linear date
in previous versions).
This commit is contained in:
Rhodri Pugh 2021-05-24 19:46:11 +01:00
parent 3f67dbe66f
commit 1cacb57cf1
2 changed files with 3 additions and 1 deletions

View File

@ -237,6 +237,8 @@ EOD;
if ($cell->isString()) {
$cellXML .= $this->getCellXMLFragmentForNonEmptyString($cell->getValue());
} elseif ($cell->isDate()) {
$cellXML .= ' t="d"><v>' . $cell->getValue()->format(\DateTimeInterface::ATOM) . '</v></c>';
} elseif ($cell->isBoolean()) {
$cellXML .= ' t="b"><v>' . (int) ($cell->getValue()) . '</v></c>';
} elseif ($cell->isNumeric()) {

View File

@ -365,7 +365,7 @@ class WriterTest extends TestCase
{
$fileName = 'test_add_row_should_support_multiple_types_of_data.xlsx';
$dataRows = $this->createRowsFromValues([
['xlsx--11', true, '', 0, 10.2, null],
['xlsx--11', true, '', 0, 10.2, null, new \DateTime('2021-01-01'), new \DateTimeImmutable('2021-02-02')],
]);
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);