Laravel Excel export multiple sheets to xlsx and pdf (landscape)
Hi,
I've got a Laravel Excel export with multiple sheets which I need to export as a xlsx and pdf, but the pdf needs to be in landscape orientation. Does anyone know how to do this on an export with multiple sheets?
Simplified code:
<?php
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class StatementExport implements WithMultipleSheets
{
use Exportable;
/**
* @return array
*/
public function sheets(): array
{
$sheets = [
new OverviewSheet($this->statements)
];
$this->statements->each(function ($statement) use (&$sheets) {
$sheets[] = new StatementSheet($statement);
});
return $sheets;
}
}
<?php
class DownloadController
{
public function __invoke()
{
$formats = ['xlsx', 'pdf'];
$export = new StatementExport($statements);
foreach ($this->formats as $format) {
$files[] = $this->store($export, $format);
}
Auth::user()->notify(new Download($files));
}
protected function store(ComposerStatementExport $export, $format)
{
$name = "statement.{$format}";
switch ($format) {
case 'xlsx':
$type = Excel::XLSX;
break;
case 'pdf':
$type = Excel::DOMPDF;
break;
default:
// TODO: Exception
break;
}
$export->store($name, null, $type);
return Storage::path($name);
}
}