Closed bugzbrown closed 5 years ago
Something interesting... I found where the problem lies!
in lines 144 -> 149 of file Sheet.php you add headings within an array:
if (!$sheetExport instanceof FromView && $sheetExport instanceof WithHeadings) {
if ($sheetExport instanceof WithCustomStartCell) {
$startCell = $sheetExport->startCell();
}
$this->append([$sheetExport->headings()], $startCell ?? null, $this->hasStrictNullComparison($sheetExport));
}
If left like this, when you use store() everything works OK If you use queue() - it does not add a heading...
If you now remove the array around headings(), the opposite occurs
Replacing the if for this will do the trick:
if (!$sheetExport instanceof FromView && $sheetExport instanceof WithHeadings) {
if ($sheetExport instanceof WithCustomStartCell) {
$startCell = $sheetExport->startCell();
}
if ($sheetExport instanceof ShouldQueue){
$this->append($sheetExport->headings(), $startCell ?? null, $this->hasStrictNullComparison($sheetExport));
}else{
$this->append([$sheetExport->headings()], $startCell ?? null, $this->hasStrictNullComparison($sheetExport));
}
}
Hi @bugzbrown ,
I'm unable to reproduce your issue. My code:
<?php
namespace App\Http\Controllers;
use App\Exports\UsersExport;
class UserController extends Controller
{
public function export()
{
(new UsersExport())->queue('users-export.xlsx');
}
}
<?php
namespace App\Exports;
use App\User;
use Illuminate\Database\Query\Builder;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
class UsersExport implements FromQuery, WithHeadings
{
use Exportable;
public function headings(): array
{
return [
'id',
'name',
'email address',
'date created',
'updated',
'something else',
];
}
public function query()
{
return User::query()->where('id', '>', '5');
}
}
I do see that in the code snippet you posted, you're referring to FormQuery
instead of FromQuery
. Could that perhaps be the issue?
Closing due to inactivity.
I am also having this issue when I upgraded from L10 to L11.
Versions PHP version: 8.3 Laravel version: 11 Package version: 3.1
I'm using export ->queue($filename)->onQueue("QueueName")
The weird thing is, in my local environment its working as expected, but when I deployed to vapor, the heading is not being exported.
Any update here? I'm seeing the exact same thing. K8s environments are missing headings only, and local is fine even when queueing.
PHP 8.3 Laravel version 10 Package 3.1.55
Versions
Description
Exporting Excel files with the WithHeadings concern does not generate a header when excel file is queued.
My exporter implements FromQuery, WithHeadings
and when I call it using store('file.xlsx')
it generates an excel perfectly with a header line.
if I call it with queue('file.xlsx') it will generate the file without the header.
Steps to Reproduce
Using a query with a simple table for example: name, age 'fred', 32; 'john', 43;
My Exporter:
My controller:
If you visit both URLs you should have two stored excels in your storage folder...
Expected behavior:
myItems.xlsx
and
myItems-queue.xlsx
Actual behavior:
myItems.xlsx
and
myItems-queue.xlsx
Additional Information
I haven't quite figured out how you go about putting the header on the file yet... so I haven't come up with a PR - if you can help guide me to where I am supposed to look at, I can try and send one in when I come up with a solution.