Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Excel export not including float values of 0.00

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. enter image description here

like image 815
Benjiro Avatar asked Dec 05 '25 06:12

Benjiro


1 Answers

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

like image 165
Alexander Braekevelt Avatar answered Dec 08 '25 00:12

Alexander Braekevelt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!