Release 2.29 (#5325)
* bump composer packages * fixes #5329 quotes for ANSI_MODE * improve year selection * improve year selection via dropdown * added range selector in month-picker * fix week number if week starts with sunday * fix first day of month in URL * predefined options for week chooser * z-index issue with sticky table header * replace duplicated translations * add logout button to allow user switch without having to re-login in "remember me" login * new flag to detect if invoice entry is a fixed rate * improve export column lengths
This commit is contained in:
@@ -17,28 +17,40 @@ use OpenSpout\Common\Entity\Style\BorderPart;
|
||||
use OpenSpout\Common\Entity\Style\Color;
|
||||
use OpenSpout\Common\Entity\Style\Style;
|
||||
use OpenSpout\Writer\AbstractWriterMultiSheets;
|
||||
use OpenSpout\Writer\CSV\Writer;
|
||||
use OpenSpout\Writer\AutoFilter;
|
||||
use OpenSpout\Writer\CSV\Writer as CSVWriter;
|
||||
use OpenSpout\Writer\WriterInterface;
|
||||
use OpenSpout\Writer\XLSX\Entity\SheetView;
|
||||
use OpenSpout\Writer\XLSX\Writer as XLSXWriter;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class SpoutSpreadsheet implements SpreadsheetPackage
|
||||
{
|
||||
private Style $dateStyle;
|
||||
|
||||
public function __construct(private readonly WriterInterface $writer)
|
||||
public function __construct(
|
||||
private readonly WriterInterface $writer,
|
||||
private readonly TranslatorInterface $translator
|
||||
)
|
||||
{
|
||||
$this->writer->setCreator(Constants::SOFTWARE);
|
||||
$this->dateStyle = (new Style())->setFormat('yyyy-mm-dd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $columns
|
||||
* @param array<Column> $columns
|
||||
*/
|
||||
public function setHeader(array $columns): void
|
||||
public function setColumns(array $columns): void
|
||||
{
|
||||
$columnCounter = \count($columns);
|
||||
if ($columnCounter === 0) {
|
||||
throw new \InvalidArgumentException('At least one column is required');
|
||||
}
|
||||
|
||||
$tmp = [];
|
||||
foreach ($columns as $column) {
|
||||
$tmp[] = Cell::fromValue($column);
|
||||
$title = $this->translator->trans($column->getHeader());
|
||||
$tmp[] = Cell::fromValue($title);
|
||||
}
|
||||
|
||||
$style = new Style();
|
||||
@@ -48,6 +60,24 @@ class SpoutSpreadsheet implements SpreadsheetPackage
|
||||
$style->setBorder(new Border(new BorderPart(Border::BOTTOM, Color::BLACK, Border::WIDTH_THIN, Border::STYLE_SOLID)));
|
||||
$style->setFontBold();
|
||||
|
||||
if ($this->writer instanceof XLSXWriter) {
|
||||
$autoFilter = new AutoFilter(0, 1, $columnCounter - 1, 1);
|
||||
$this->writer->getCurrentSheet()->setAutoFilter($autoFilter);
|
||||
|
||||
$options = $this->writer->getOptions();
|
||||
|
||||
$i = 1;
|
||||
foreach ($columns as $column) {
|
||||
$width = match($column->getColumnWidth()) {
|
||||
ColumnWidth::SMALL => 10,
|
||||
ColumnWidth::MEDIUM => 30,
|
||||
ColumnWidth::LARGE => 50,
|
||||
default => 15,
|
||||
};
|
||||
$options->setColumnWidth($width, $i++);
|
||||
}
|
||||
}
|
||||
|
||||
$this->writer->addRow(new Row($tmp, $style));
|
||||
}
|
||||
|
||||
@@ -62,7 +92,7 @@ class SpoutSpreadsheet implements SpreadsheetPackage
|
||||
$style->setShouldShrinkToFit(true);
|
||||
|
||||
if (\array_key_exists('totals', $options) && $options['totals'] === true) {
|
||||
if ($this->writer instanceof Writer) {
|
||||
if ($this->writer instanceof CSVWriter) {
|
||||
return;
|
||||
}
|
||||
$style->setBorder(new Border(new BorderPart(Border::TOP, Color::BLACK, Border::WIDTH_THIN, Border::STYLE_SOLID)));
|
||||
|
||||
Reference in New Issue
Block a user