Contract reference text format inside exported excel

This commit is contained in:
Simon Pocrnjič
2025-12-10 21:15:53 +01:00
parent 53941c054e
commit 79de54eef0
2 changed files with 14 additions and 2 deletions
+12 -1
View File
@@ -11,11 +11,14 @@
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class SegmentContractsExport implements FromQuery, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping
{
public const DATE_EXCEL_FORMAT = 'dd"."mm"."yyyy';
public const TEXT_EXCEL_FORMAT = NumberFormat::FORMAT_TEXT;
/**
* @var array<string, array{label: string}>
*/
@@ -76,8 +79,16 @@ public function columnFormats(): array
$formats = [];
foreach ($this->columns as $index => $column) {
$letter = $this->columnLetter($index);
if ($column === 'reference') {
$formats[$letter] = self::TEXT_EXCEL_FORMAT;
continue;
}
if (in_array($column, ['start_date', 'end_date'], true)) {
$formats[$this->columnLetter($index)] = self::DATE_EXCEL_FORMAT;
$formats[$letter] = self::DATE_EXCEL_FORMAT;
}
}