Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export excel with custom headers #8

Open
roxozur opened this issue Aug 15, 2019 · 1 comment
Open

export excel with custom headers #8

roxozur opened this issue Aug 15, 2019 · 1 comment

Comments

@roxozur
Copy link

roxozur commented Aug 15, 2019

i have this piece of code

memberController.php

  $serialiser = new Serialiser();
  $excel = Exporter::make('Excel');
        $excel->loadQuery($query);
       $excel->setSerialiser($serialiser);
        return $excel->stream('Members.xlsx');

and i made a class inside App\CustomClass\

use namespace App\CustomClass;
classs Serialiser implements SerialserInterface
{
 public function getData($data)
    {
        $row = [];

        $row[] = $data->field1;
        $row[] = $data->field2;
        $row[] = $data->field3;

        return $row;
    }

    public function getHeaderRow()
    {
        return [
            'Field 1',
           'Field 2',
           'Field 3',
        ];
    }

}

but this does not seem to work

@abosaqr
Copy link

abosaqr commented Oct 24, 2019

You could just extend the basic serialiser, and override what you need

namespace App\Serialisers; use Illuminate\Database\Eloquent\Model; // use Cyberduck\LaravelExcel\Contract\SerialiserInterface; use Cyberduck\LaravelExcel\Serialiser\BasicSerialiser; class CustomSerialiser extends BasicSerialiser { public function getHeaderRow() { return [ 'header field 1', 'header field 2', 'header field 3', ]; } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants