writer->setCreator(Constants::SOFTWARE); $this->dateStyle = (new Style())->setFormat('yyyy-mm-dd'); } /** * @param array $columns */ public function setHeader(array $columns): void { $tmp = []; foreach ($columns as $column) { $tmp[] = Cell::fromValue($column); } $style = new Style(); $style->setShouldWrapText(false); $style->setShouldShrinkToFit(true); $style->setBackgroundColor('EEEEEE'); $style->setBorder(new Border(new BorderPart(Border::BOTTOM, Color::BLACK, Border::WIDTH_THIN, Border::STYLE_SOLID))); $style->setFontBold(); $this->writer->addRow(new Row($tmp, $style)); } /** * @param array $columns * @param array $options */ public function addRow(array $columns, array $options = []): void { $style = new Style(); $style->setShouldWrapText(false); $style->setShouldShrinkToFit(true); if (\array_key_exists('totals', $options) && $options['totals'] === true) { if ($this->writer instanceof Writer) { return; } $style->setBorder(new Border(new BorderPart(Border::TOP, Color::BLACK, Border::WIDTH_THIN, Border::STYLE_SOLID))); $style->setFontBold(); } $tmp = []; foreach ($columns as $column) { 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)); } public function open(string $filename): void { $this->writer->openToFile($filename); if ($this->writer instanceof AbstractWriterMultiSheets) { $sheetView = new SheetView(); $sheetView->setFreezeColumn('D'); $sheetView->setFreezeRow(2); $this->writer->getCurrentSheet()->setSheetView($sheetView); } } public function save(): void { $this->writer->close(); } }