mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-13 21:35:19 +02:00
fix: support more than 25 columns in data export sheets (#205)
range('A', ...) silently truncates its end argument to one byte once a
sheet needs a column past 'Z' (e.g. 26+ questions), triggering a PHP
warning and mis-sizing columns. Replace it with a helper that walks
column indexes via Coordinate::stringFromColumnIndex, which handles
multi-letter columns correctly.
Fixes PHP-SYMFONY-3Z
This commit is contained in:
@@ -263,7 +263,7 @@ class DataExportService
|
||||
}
|
||||
|
||||
$lastColumnIndex = 1 + \count($questions);
|
||||
foreach (range('A', Coordinate::stringFromColumnIndex($lastColumnIndex)) as $column) {
|
||||
foreach ($this->columnLetters($lastColumnIndex) as $column) {
|
||||
$sheet->getColumnDimension($column)->setWidth(30);
|
||||
$sheet->getStyle($column.':'.$column)->getAlignment()->setWrapText(true);
|
||||
}
|
||||
@@ -297,7 +297,7 @@ class DataExportService
|
||||
++$row;
|
||||
}
|
||||
|
||||
foreach (range('A', Coordinate::stringFromColumnIndex(2 + \count($candidates))) as $column) {
|
||||
foreach ($this->columnLetters(2 + \count($candidates)) as $column) {
|
||||
$sheet->getColumnDimension($column)->setAutoSize(true);
|
||||
}
|
||||
}
|
||||
@@ -405,7 +405,7 @@ class DataExportService
|
||||
}
|
||||
|
||||
$lastColumnIndex = $answerStartColumnIndex + max(1, 2 * $maxAnswers);
|
||||
foreach (range('A', Coordinate::stringFromColumnIndex($lastColumnIndex)) as $column) {
|
||||
foreach ($this->columnLetters($lastColumnIndex) as $column) {
|
||||
$sheet->getColumnDimension($column)->setAutoSize(true);
|
||||
}
|
||||
}
|
||||
@@ -426,6 +426,22 @@ class DataExportService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Column letters from 'A' up to and including the given 1-based column index.
|
||||
* Unlike range('A', ...), this works past 'Z' (e.g. index 27 => 'AA').
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function columnLetters(int $lastColumnIndex): array
|
||||
{
|
||||
$letters = [];
|
||||
for ($columnIndex = 1; $columnIndex <= $lastColumnIndex; ++$columnIndex) {
|
||||
$letters[] = Coordinate::stringFromColumnIndex($columnIndex);
|
||||
}
|
||||
|
||||
return $letters;
|
||||
}
|
||||
|
||||
/** @throws FilesystemException */
|
||||
private function writeToTempFile(Spreadsheet $spreadsheet): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user