Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rahul95's avatar
Level 15

Laravel Excel - How to set the sheet name

Hi,

I'm using Laravel Excel package to create a csv file that we then use on a third party application to process a bulk payment action. This is the screenshot of the csv file i'm exporting,

Screenshot

The problem i'm having here is with the sheet name. The third-party software will accept the doc only if the sheet name is bank_account. but here, the filename is turning out to be the sheet name. Since i'm saving the generated docs in the server i can't simply turn the filename into bank_account

What i have tried

I have used the laravel excel's WithTitle (reference from, https://github.com/Maatwebsite/Laravel-Excel/issues/1585 ) but it doesn't seems to work.

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithTitle;

class CashfreeBatchExport implements FromArray, WithTitle
{
    protected $entries;

    public function __construct(array $entries)
    {
        $this->entries = $entries;
    }

    /**
    * @return \Illuminate\Support\Array
    */
    public function array(): array
    {
        return $this->entries;
    }

    public function title(): string
    {
        return 'bank_account';
    }
}

And this is my controller,

$export = new BatchExport($data);
$filename = uniqid('arx_cashfree_trbtch_') . '.csv';
Excel::store($export, 'public/transfer-batch-docs/' . $filename);

Do u guys have any idea o how to set the sheet name ?

Thanks in advance.

0 likes
1 reply
rodrigo.pedra's avatar

As you are using .csv extension Laravel-Excel will save it as a CSV file, which is basically a text file and not a true excel file.

Try using a .xlsx extension.

For example:

$export = new BatchExport($data);
$filename = uniqid('arx_cashfree_trbtch_') . '.xlsx'; // changed here
Excel::store($export, 'public/transfer-batch-docs/' . $filename);

Please or to participate in this conversation.