I am exporting to excel using "maatwebsite/excel": "^3.1", but when I export, columns with values 0 or 0.0 are ignored and the cell is left empty. sample code:
public function array(): array
{
return $this->data;
}
public function columnFormats(): array
{
return [
'C' => NumberFormat::FORMAT_TEXT,
'E' => '0.00',
'F' => '0.00',
'G' => '0.00'
];
}
public function map($rows): array
{
return [
$rows['employeeNumber'],
$rows['basicSalary'],
$rows['totalAllowance'],
$rows['grossSalary']
];
}
when values for the columns are 0 or 0.00, nothing is inserted in the cell.

You can use WithStrictNullComparison (as @Sirapat already said)
class YourExport implements WithStrictNullComparison
https://docs.laravel-excel.com/3.1/exports/collection.html#strict-null-comparisons
Or you can change the excel.php config file:
'strict_null_comparison' => true // New format
'strictNullComparison' => true // Old format
https://laracasts.com/discuss/channels/laravel/have-0-instead-of-null-or-empty-cell-in-laravel-excel-appendrows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With