php - Laravel: how to change startcell when exporting using a template file
one text
Laravel Framework 5.8.38
maatwebsite/excel 3.1.19
I'm trying to export using a template file.
the following code is working but "startCell()" doesn't seem to work.
it's always start from "A6" in export file.
how should i do in this case.
class TestExport implements FromQuery, WithEvents, WithCustomStartCell, WithStrictNullComparison
{
public function setTemplate(string $template_file)
{
if (file_exists($template_file)) {
$this->template_file = $template_file;
}
return $this;
}
public function startCell(): string
{
return 'A3';
}
public function registerEvents(): array
{
return [
BeforeExport::class => function (BeforeExport $event) {
if (is_null($this->template_file)) {
return;
}
$event->writer->reopen(new LocalTemporaryFile($this->template_file), Excel::XLSX);
$event->writer->getSheetByIndex(0);
$this->calledByEvent = true;
$event->writer->getSheetByIndex(0)->export($event->getConcernable());
return $event->getWriter()->getSheetByIndex(0);
},
BeforeWriting::class => function (BeforeWriting $event) {
$event->writer->removeSheetByIndex(1);
return;
},
];
}
}
Source