-2

I use Laravel Excel.

The code builds excel file and does export to path $path.$filename:

  Excel::store(new VisitorsExport($request), $path.$filename);

Could I iterate all rows before Excel::store?

POV
  • 11,293
  • 34
  • 107
  • 201

1 Answers1

0

You can add WithMapping to your export so you can define a map() function that accept a row and return an array, so you can iterate and trasform all of your rows, this is an example with the Eloquent query builder:

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithMapping;

class VisitorsExport implements FromQuery, WithMapping
{    

    public function map($visitor): array
    {
        return [
            $visitor->id,
            $visitor->name,
            Date::dateTimeToExcel($visitor->created_at),
        ];
    }
}

You can read the complete docs on mapping here.

dparoli
  • 8,891
  • 1
  • 30
  • 38
  • I need styling not mapping, could you explain how to style rows/cell before exporting – POV Aug 07 '19 at 19:23
  • 1
    You asked to iterate over all rows and map is an iterator, if your need was styling please update your question, as written your needs are not clear – dparoli Aug 07 '19 at 19:26