'Laravel excel export - string formatted column showing as number

In localhost i can set the column format as PHPExcel_Cell_DataType::TYPE_STRING and its working fine here is the .xls file by using this type

enter image description here

how ever if i test this in live i get something like enter image description here

column values set to 0.

Why i have tried PHPExcel_Cell_DataType::TYPE_STRING format is because the string like 65081035703021 showing as number (base 10) in ms-excel

Whats goes wrong for me?

enter image description here



Solution 1:[1]

try this code

namespace App\Exports;

use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMapping;

class InvoicesExport implements WithColumnFormatting, WithMapping
{
    public function map($invoice): array
    {
        return [
            $invoice->invoice_number,
            Date::dateTimeToExcel($invoice->created_at),
            $invoice->total
        ];
    }

    public function columnFormats(): array
    {
        return [
            'B' => NumberFormat::FORMAT_DATE_DDMMYYYY,
            'C' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
        ];
    }
}

Reference

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cuong Le Ngoc