Laravel-Excel icon indicating copy to clipboard operation
Laravel-Excel copied to clipboard

[Bug]: Doesn't ignore multiple sheets even when not using `withMultipleSheets`

Open ChrisToxz opened this issue 7 months ago • 1 comments
trafficstars

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

  • [x] Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1

What version of Laravel are you using?

12

What version of PHP are you using?

8.4

Describe your issue

It might be by design, but in my opinion its a bug, or at least an unlogical flow.

Currently if your workbook has multiple sheets, all sheets will be handle by the import class. In my opinion this behaviour should only happen when you implement the WithMultipleSheets concern. As the name already specifiy, this concern is used, when you have/want multiple sheets to processes

Now when an file has multiple sheets (if not by accident), the imports are highly likely to fail, due validation or other reasons. A work around is to add below snippet to each import class

class ProductImport implements WithMultipleSheets
{
    public function sheets(): array
    {
        return [
            0 => $this,
        ];
    }

Where the naming is also very contradictory, implementing 'WithMultipleSheets', to avoid processing multiple sheets. I would expect without this concern, multiple sheets are completely ignored.

How can the issue be reproduced?

Import file with multiple sheets.

What should be the expected behaviour?

  • Only process the first sheet, if WithMultipleSheets is not implemented
  • Process all sheets, if WithMultipleSheets is implemented

ChrisToxz avatar Apr 07 '25 13:04 ChrisToxz

class ProductImport implements WithMultipleSheets
{
    public function sheets(): array
    {
        return [
            0 => $this,
        ];
    }

is the correct way of doing this.

Behaviour has been like this since the release in 2018 and not likely to change as this might cause an unexpected breaking change.

I'm open to accept a PR for a WithSingleSheet concern

patrickbrouwers avatar Jun 02 '25 16:06 patrickbrouwers

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.

stale[bot] avatar Aug 02 '25 18:08 stale[bot]