Laravel-excel: Merge cell doesn't work in 3.0 version

Created on 24 Sep 2018  ·  3Comments  ·  Source: Maatwebsite/Laravel-Excel

Versions

  • PHP version: 7.2
  • Laravel version: 5.6
  • Package version: 3.0

Description

Steps to Reproduce

public function machineryExport()
{

    return Excel::download(new MachineryExport, 'machinery.csv');
}

my machineryexport look like

class MachineryExport implements FromView
{
    /**
     * @return \Illuminate\Support\Collection
     */
    public function view(): View
    {
        return view('export.machinery', [
            'equipments' => MachineryEquipment::get()
        ])->mergeCells('A1:E1');
    }
}

I want to merge the cell A1 and A2 but i cant and colspan and row span also not worked

question

Most helpful comment

Hey @kevinRR, where did you find this syntax? 3.0 doesn't have a mergeCells method and Laravel's view() helper doesn't have it either.

In the current state of the package you'll have to follow the extending docs (https://laravel-excel.maatwebsite.nl/3.0/exports/extending.html#events) and use the native ->mergeCells('A1:E1') method of PhpSpreadsheet. The AfterSheet event is what you're looking for.

AfterSheet::class => function(AfterSheet $event) {
    $event->sheet->getDelegate()->mergeCells('A1:E1');
 },

All 3 comments

Hey @kevinRR, where did you find this syntax? 3.0 doesn't have a mergeCells method and Laravel's view() helper doesn't have it either.

In the current state of the package you'll have to follow the extending docs (https://laravel-excel.maatwebsite.nl/3.0/exports/extending.html#events) and use the native ->mergeCells('A1:E1') method of PhpSpreadsheet. The AfterSheet event is what you're looking for.

AfterSheet::class => function(AfterSheet $event) {
    $event->sheet->getDelegate()->mergeCells('A1:E1');
 },

This is my export file so how can i merge cell while passing to the view from my Export file

public function view(): View
    {
        return view('export.machinery', [
            'equipments' => MachineryEquipment::get()
        ]);
    }

I gave you the solution in my previous comment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amine8ghandi8amine picture amine8ghandi8amine  ·  3Comments

alejandri picture alejandri  ·  3Comments

lucatamtam picture lucatamtam  ·  3Comments

ellej16 picture ellej16  ·  3Comments

pamekar picture pamekar  ·  3Comments