Laravel Excel 导出不包括 0.00 的浮点值

Ben*_*iro 1 laravel maatwebsite-excel

我使用 "maatwebsite/excel": "^3.1" 导出到 Excel,但是当我导出时,值为 0 或 0.0 的列将被忽略,并且单元格留空。示例代码:

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']
    ];
}
Run Code Online (Sandbox Code Playgroud)

当列的值为 0 或 0.00 时,单元格中不会插入任何内容。 在此输入图像描述

Ale*_*elt 5

你可以使用WithStrictNullComparison(正如@Sirapat已经说过的)

class YourExport implements WithStrictNullComparison
Run Code Online (Sandbox Code Playgroud)

https://docs.laravel-excel.com/3.1/exports/collection.html#strict-null-comparisons

或者您可以更改excel.php配置文件:

'strict_null_comparison' => true // New format
'strictNullComparison' => true   // Old format
Run Code Online (Sandbox Code Playgroud)

https://laracasts.com/discuss/channels/laravel/have-0-instead-of-null-or-empty-cell-in-laravel-excel-appendrows