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:
parent
3f67dbe66f
commit
1cacb57cf1
@ -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()) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user