Again contract format problem in excel export fixed now!
This commit is contained in:
parent
79de54eef0
commit
aa40ebed5c
|
|
@ -8,17 +8,26 @@
|
|||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class SegmentContractsExport implements FromQuery, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping
|
||||
class SegmentContractsExport extends DefaultValueBinder implements FromQuery, ShouldAutoSize, WithColumnFormatting, WithCustomValueBinder, WithHeadings, WithMapping
|
||||
{
|
||||
public const DATE_EXCEL_FORMAT = 'dd"."mm"."yyyy';
|
||||
|
||||
public const TEXT_EXCEL_FORMAT = NumberFormat::FORMAT_TEXT;
|
||||
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private array $columnLetterMap = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array{label: string}>
|
||||
*/
|
||||
|
|
@ -78,9 +87,7 @@ public function columnFormats(): array
|
|||
{
|
||||
$formats = [];
|
||||
|
||||
foreach ($this->columns as $index => $column) {
|
||||
$letter = $this->columnLetter($index);
|
||||
|
||||
foreach ($this->getColumnLetterMap() as $letter => $column) {
|
||||
if ($column === 'reference') {
|
||||
$formats[$letter] = self::TEXT_EXCEL_FORMAT;
|
||||
|
||||
|
|
@ -133,4 +140,31 @@ private function columnLetter(int $index): string
|
|||
|
||||
return $letter;
|
||||
}
|
||||
|
||||
public function bindValue(Cell $cell, $value): bool
|
||||
{
|
||||
$columnKey = $this->getColumnLetterMap()[$cell->getColumn()] ?? null;
|
||||
|
||||
if ($columnKey === 'reference') {
|
||||
$cell->setValueExplicit((string) $value, DataType::TYPE_STRING);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::bindValue($cell, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getColumnLetterMap(): array
|
||||
{
|
||||
if ($this->columnLetterMap === []) {
|
||||
foreach ($this->columns as $index => $column) {
|
||||
$this->columnLetterMap[$this->columnLetter($index)] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->columnLetterMap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user