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]: FromArray exports only 1000 rows #4162

Open
1 task done
ItprojektRepo opened this issue Jul 9, 2024 · 5 comments
Open
1 task done

[Bug]: FromArray exports only 1000 rows #4162

ItprojektRepo opened this issue Jul 9, 2024 · 5 comments
Labels

Comments

@ItprojektRepo
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.55

What version of Laravel are you using?

11.10.0

What version of PHP are you using?

8.2.7

Describe your issue

FromArray export has only 1000 rows and only last data is present.
Found that problem is in Sheet.php -> appendRows function
It chunks 1000 and every time starts from cell A1. Meaning it overwrites existing data instead of appending

`public function appendRows($rows, $sheetExport)
{
if (method_exists($sheetExport, 'prepareRows')) {
$rows = $sheetExport->prepareRows($rows);
}

    $rows = $rows instanceof LazyCollection ? $rows : new Collection($rows);

    $rows->flatMap(function ($row) use ($sheetExport) {
        if ($sheetExport instanceof WithMapping) {
            $row = $sheetExport->map($row);
        }

        if ($sheetExport instanceof WithCustomValueBinder) {
            SpreadsheetCell::setValueBinder($sheetExport);
        }

        return ArrayHelper::ensureMultipleRows(
            static::mapArraybleRow($row)
        );
    })->chunk(1000)->each(function ($rows) use ($sheetExport) {
        $this->append(
            $rows->toArray(),
            $sheetExport instanceof WithCustomStartCell ? $sheetExport->startCell() : null,
            $this->hasStrictNullComparison($sheetExport)
        );
    });
}`

In here changing ->chunk(1000) to ->chunk(10000) prints all data

Reproducing:
Export array that has more than 1000 rows. Using FromArray.

Currently using Concerns FromArray, WithTitle, WithCustomValueBinder

How can the issue be reproduced?

Reproducing:
Export array that has more than 1000 rows. Using FromArray.

Currently using Concerns FromArray, WithTitle, WithCustomValueBinder

What should be the expected behaviour?

First rows are overwritten by rows that are over 1000

@ItprojektRepo
Copy link
Author

Update.

First cell has to have a value in it.
I had cell A1 empty and then it occured. If I put random valu in there then everything works.

So problem is instead in hasRows function
`private function hasRows(): bool
{
$startCell = 'A1';
if ($this->exportable instanceof WithCustomStartCell) {
$startCell = $this->exportable->startCell();
}

    return $this->worksheet->cellExists($startCell);
}

`

@owaishussain
Copy link

@ItprojektRepo is it resolved on your end?

@kukumagi
Copy link

kukumagi commented Aug 5, 2024

@ItprojektRepo is it resolved on your end?

I filled A1 cell with a static value for it to work. If I leave it blank then it overwrites first 1000 rows. And looking at this logic it will always overwrite every 1000 rows if I would have a blank value in column A.

So I simply made changes so my code would work, but the bug still exists.

@iactor
Copy link

iactor commented Aug 16, 2024

Replacing blank data with non blank data, such as "-", can solve the problem

@patrickbrouwers
Copy link
Member

I don't see an easy other way to check if we are inserting in the first row, or if we are appending. If someone has a better way of doing this, please create a PR :)

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

5 participants