Are you implementing WithTitle in each of your Spreadsheet classes?
See this example from the dos: https://docs.laravel-excel.com/3.1/exports/multiple-sheets.html#sheet-classes
Hello , i have a problem with laravel-excel package, when exporting some data to an excel file for multiple sheets the heading don't show up , before that it was working before was only one sheet . any one has faced the same problem before ?? ican't find an answer in docs , it toke from a long time to find a solution , but nothing yet .
I'm not sure what the issue is then. Here's an example of multiple sheets with headings working in one of my projects. Maybe you can use it to compare/contrast and find the issue.
Controller:
...
$export = new ReportExport($data['data']);
return Excel::download($export, 'report.xlsx');
Parent sheet:
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class ReportExport implements FromArray, WithMultipleSheets
{
protected $sheets;
public function __construct(array $sheets)
{
$this->sheets = $sheets;
}
public function array(): array
{
return $this->sheets;
}
public function sheets(): array
{
$sheets = [
new ReportGeneralExport($this->sheets['general']),
new ReportLeadsExport($this->sheets['leads']),
new ReportVideoExport($this->sheets['video'])
];
return $sheets;
}
}
Child sheet:
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithMapping;
class ReportGeneralExport implements FromArray, WithHeadings, WithTitle, ShouldAutoSize, WithColumnFormatting, WithMapping
{
protected $rows;
public function __construct(array $rows)
{
$this->rows = $rows;
}
public function map($row): array
{
return [
$row['name'],
$row['impressions'],
$row['clicks'],
$row['ctr']
];
}
public function headings(): array
{
return [
'Name',
'Impressions',
'Clicks',
'CTR'
];
}
public function array(): array
{
return $this->rows;
}
public function title(): string
{
return 'General';
}
public function columnFormats(): array
{
return [
'B' => '#,##0',
'C' => '#,##0',
'D' => NumberFormat::FORMAT_PERCENTAGE_00
];
}
}
Hope this helps.
Please or to participate in this conversation.