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

seco's avatar
Level 1

exactly @jimmck as the previous code i wrote showing how i export to excel

Snapey's avatar

Sorry, I don't know how you write to excel. Which library is it?

I'm surprised it uses table cells? Is there not a fromArray method?

seco's avatar
Level 1

@Snapey the library is called Maatwebsite i think i saw before fromArray but i was unable to use it that way

and don't know what is the difference

in my case how i can write fromArray method ?

seco's avatar
Level 1

@Snapey guess what i use from array like this

$province=Province::with('country')->orderBy('name','ASC')->get();

Excel::create($this->reportTitle, function($excel) use ($province) {
                $excel->sheet($this->reportTitle, function($sheet) use ($province) {
                   $provinces=$province->toArray();
                        $sheet->fromArray($provinces);
                });
          })->download('xls');

it takes double time when using fromArray !!!

Snapey's avatar

http://www.maatwebsite.nl/laravel-excel/docs/export#array

you just need to concentrate on getting your data from the collection with relationships into a plain array.

I would have thought this would be a lot quicker than rendering a view as html and then asking phpExcel to import it as html and convert to cell data?

1 like
seco's avatar
Level 1

@Snapey using fromArray method as above took 1.4 minutes while rendering view as html took 41 seconds !!

Snapey's avatar

wow. I render a 256 page PDF with 2500 names and addresses in less time than that. Something is not right....

jimmck's avatar

@Snapey The OP needs to better understand their tools. Like you I write directly using PHPOffice Excel with no problems.

Previous

Please or to participate in this conversation.