Hello, good work on this package, it's really nice to use.
I'm encountering an issue with 1.3 on laravel 4.2 when using wrap-text:true (either in external css or inline) on td tags.
When exporting ~4k rows with 9 columns without it, it takes more or less 10 seconds to output.
When setting wrap-text:true, the same export will take no less than 20+ seconds.
Now, I am fairly new to laravel in general, and it might be my mistake, but is there anything to be done to improve that?
In the controller I have:
public function export(){
Excel::create('Contacts', function($excel) {
$contacts = Contact::orderBy('name', 'asc')->get();
$excel->sheet('Contacts', function($sheet) use ($contacts){
$sheet->loadView('contacts.export')->with(["contacts" => $contacts]);
});
$excel->export('xls');
});
};
And my contacts/export.blade.php ressembles this _(trimmed down for clarity, it has 9 columns)_
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
{{ HTML::style('css/export.css'); }}
</head>
<body>
@if ($contacts->count())
<table>
<tr>
<th>Name</th>
<th>Organization</th>
</tr>
@foreach ($contacts as $contact)
<tr>
<td>
{{ $contact->name }}
</td>
<td>
{{ $contact->organization }}
</td>
</tr>
@endforeach
</table>
@endif
</body>
</html>
export.css is basically 3 lines:
td {
height:30;
width:30;
wrap-text:true;
}
So, is it any of my doing or is it just the wrap-text property that's causing the long processing?
Thanks !
I think wrap-text is indeed a performance heavy operation. Especially when it has to be set through a css selector on 4k rows.
Alternatively you can use the PHPExcel method setWrapText(). This does exactly the same as the cs selector, but instead you only call it once instead of 4000x.
$sheet->getStyle('A1:B' . $sheet->getHighestRow())
->getAlignment()->setWrapText(true);
Yes, that did the trick indeed.
In my case, calling getHighestRow() on $sheet would return 1 though, so if anyone's having this problem you need to call it on the $excel object after loading the view.
$excel->sheet('Contacts', function($sheet) use ($contacts){
$sheet->loadView('contacts.export')->with(["contacts" => $contacts]);
});
$lastrow= $excel->getActiveSheet()->getHighestRow();
$excel->getActiveSheet()->getStyle('A1:J'.$lastrow)->getAlignment()->setWrapText(true);
$excel->export('xls');
Thanks for the help!
Most helpful comment
Yes, that did the trick indeed.
In my case, calling getHighestRow() on $sheet would return 1 though, so if anyone's having this problem you need to call it on the $excel object after loading the view.
Thanks for the help!