Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Table first rows render in top-left cell if first cell in header is empty. #4286

Open
1 task done
boxsnake opened this issue Mar 24, 2025 · 1 comment
Open
1 task done
Labels

Comments

@boxsnake
Copy link

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.62

What version of Laravel are you using?

11.36.1

What version of PHP are you using?

8.3.17

Describe your issue

When exporting excel, if WithHeadings and WithMapping are used, if headings() returned with first cell empty (null or ''), the first row will be written to top-left cell of heading (and overwrite heading cells).

How can the issue be reproduced?

<?php

class Demo implements
    WithHeadings,
    FromCollection,
    WithMapping
{
    protected Collection $rows;

    public function __construct(
        Collection $rows
    ) {
        $this->rows= $rows;
    }

    public function headings(): array
    {
        return [
            '',
            'Header'
        ];
    }

    public function collection()
    {
        return $this->rows;
    }

    public function map($row): array
    {
        return [
            $row->field
        ];
    }
}

This will product with $row->field rendered in cell A1.

What should be the expected behaviour?

The $row->field rendered to cell A2 with on row of header.

@boxsnake boxsnake added the bug label Mar 24, 2025
@patrickbrouwers
Copy link
Member

Try to put a space (or something non-empty) in the first cell, unfortunatly there's no other good way to determine if the first row has already been used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants