fix date column in export (#5308)

This commit is contained in:
Kevin Papst
2025-01-20 16:09:29 +01:00
committed by GitHub
parent f2fb338539
commit 9d7b418d99
7 changed files with 128 additions and 24 deletions

View File

@@ -23,9 +23,12 @@ use OpenSpout\Writer\XLSX\Entity\SheetView;
class SpoutSpreadsheet implements SpreadsheetPackage
{
private Style $dateStyle;
public function __construct(private readonly WriterInterface $writer)
{
$this->writer->setCreator(Constants::SOFTWARE);
$this->dateStyle = (new Style())->setFormat('yyyy-mm-dd');
}
/**
@@ -68,7 +71,11 @@ class SpoutSpreadsheet implements SpreadsheetPackage
$tmp = [];
foreach ($columns as $column) {
$tmp[] = Cell::fromValue($column); // @phpstan-ignore argument.type
if ($column instanceof \DateTimeInterface) {
$tmp[] = Cell::fromValue($column, $this->dateStyle);
} else {
$tmp[] = Cell::fromValue($column); // @phpstan-ignore argument.type
}
}
$this->writer->addRow(new Row($tmp, $style));