Closed tedslittlerobot closed 5 years ago
Hey @tedslittlerobot , thanks for submitting the issue (and especially how thorough, really appreciate that!). I think it's indeed something that wasn't implemented yet (combination start row, heading row). I'll look into this soon. If in the meantime you find a good fix, feel free to PR it!
Hello, I suffered with the same, to solve it while a PR you can use AfterSheet
In your AppServiceProvider -> register
Sheet::macro('styleCells', function (Sheet $sheet, string $cellRange, array $style) {
$sheet->getDelegate()->getStyle($cellRange)->applyFromArray($style);
});
Use WithEvents concerns
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->setCellValue('A1', 'EMPRESA');
},
];
};
Will be fixed in next release
Is this fixed?
Fix has been released yes
In summary the solution is: version 3.1
public function startCell(): string
{
return 'B2';
}
how is the solution?
@patrickbrouwers The problem persists if you work with the ShouldQueue
interface.
@patrickbrouwers The problem persists if you work with the
ShouldQueue
interface.
How is the solution?
Prerequisites
Versions
Description
If you have a custom start cell of, say B2, and headers defined, both the header and the data rows will start from B2, so the latter will overwriting the former.
Steps to Reproduce
Sample Export class:
Expected behavior:
The headers, and the data, all starting at cell B2
Actual behavior:
Only the data rendered at B2:
Also relevant, as a kind of proof of explanation, is that if you comment out the actual data rows in the above class, you get:
What is happening is that the data rows are overwriting the header rows.
I believe the cause of this is in
Maatwebsite\Excel\Sheet@hasRows
. The method is declared:The starting cell of
A1
is hardcoded, and does not respect the custom start cell.Possible fix: use the custom start cell value as the cell to check against, otherwise, use A1 as a default value.
Other possible fix: don't check for a single cell to test if there is a header row, test against the
WithHeadings
interface - which implies that there will be a row there.Additional Information
Unconfirmed, but there still may be a related issue: In the method
Maatwebsite\Excel\Sheet@append
, the startCell is set (if there are already rows - ie. a header row) to$startCell = 'A' . ($this->worksheet->getHighestRow() + 1);
- i believe that this should start from the custom start cell column (or perhaps resolve it by checking for the first column with content, defaulting toA
?)