Laravel Excel Reader does not ignore empty strings #3829
Unanswered
KarinaRashchynskaya
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.phpregisterEvents
public function registerEvents(): array { return [SampleExample.xlsx](https://github.com/SpartnerNL/Laravel-Excel/files/10207125/SampleExample.xlsx) [ BeforeImport::class => function (BeforeImport $event) { return $event->getReader()->getPhpSpreadsheetReader()->setReadEmptyCells(false); } ];}
I noticed that the calculation of total rows is coming from the function
listWorksheetInfo
which is into vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Xlsx.phpThe 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.
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.xlsx
Beta Was this translation helpful? Give feedback.
All reactions