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]: Laravel Excel Reader does not ignore empty strings #3830

Closed
1 task done
KarinaRashchynskaya opened this issue Dec 13, 2022 · 1 comment
Closed
1 task done

Comments

@KarinaRashchynskaya
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

What version of Laravel are you using?

9.41

What version of PHP are you using?

8.1.0

Describe your issue

Hello,

I am trying to read the data of a XLSX file and import them into DB. Until now, I produced excel files using my LibreOffice and the SkipsEmptyRows interface in order to read file line by line and ignore empty rows. However, when I created the same Excel file with the same data in Google Docs, for some reason empty rows are not ignored. After some research, I found that google docs create rows with an empty string. Please find below a file example with this problem.

So, my question is how can I skip rows / cells which include empty strings ?

I tried the following but with no success

  • Update the variable ignore_empty => true, in config/excel.php

  • registerEvents

public function registerEvents(): array { return [ BeforeImport::class => function (BeforeImport $event)
{ return $event->getReader()->getPhpSpreadsheetReader()->setReadEmptyCells(false); } ];

Screenshot from 2022-12-12 12-49-04

Screenshot from 2022-12-12 12-48-41

I noticed that the calculation of total rows is coming from the function listWorksheetInfo which is into vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Xlsx.php

Screenshot from 2022-12-12 13-27-00

The weird thing here is that while it's reading the file and storing the total numbers of rows, it jumps suddenly from "real" total number of rows to a "magic" number of rows.

Screenshot from 2022-12-12 13-30-10

Does anyone have explanation about this? Or how can I manage it in order to ignore these empty lines?

Extra Note : I am using the WithChunkReading interface in order to keep the memory usage under control & OnEachRow interface in order to process each row's data

SampleExample (1).xlsx

How can the issue be reproduced?

To set a counter about the total number of rows instead of reading $xml->getAttribute('r')

What should be the expected behaviour?

In this case the total of number of rows should be 15 and not 1048576

@stale
Copy link

stale bot commented Feb 12, 2023

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 stale bot closed this as completed Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant