Skip to content

Commit 9c8a743

Browse files
authored
Merge pull request #4163 from homersimpsons/chore/deprecate-skip-empty-cells
🗑️ Deprecate `IReader::SKIP_EMPTY_CELLS`
2 parents 457b61c + 1befd3d commit 9c8a743

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

docs/topics/reading-and-writing-to-file.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,19 +1113,19 @@ Flags that are available that can be passed to the Reader in this way include:
11131113

11141114
- $reader::LOAD_WITH_CHARTS
11151115
- $reader::READ_DATA_ONLY
1116-
- $reader::IGNORE_EMPTY_CELLS
1117-
- $reader::SKIP_EMPTY_CELLS (synonym for IGNORE_EMPTY_CELLS)
1118-
1119-
| Readers | LOAD_WITH_CHARTS | READ_DATA_ONLY | IGNORE_EMPTY_CELLS |
1120-
|----------|------------------|----------------|--------------------|
1121-
| Xlsx | YES | YES | YES |
1122-
| Xls | NO | YES | YES |
1123-
| Xml | NO | NO | NO |
1124-
| Ods | NO | YES | NO |
1125-
| Gnumeric | NO | YES | NO |
1126-
| Html | N/A | N/A | N/A |
1127-
| Slk | N/A | NO | NO |
1128-
| Csv | N/A | NO | NO |
1116+
- $reader::IGNORE_EMPTY_CELLS
1117+
- $reader::IGNORE_ROWS_WITH_NO_CELLS
1118+
1119+
| Readers | LOAD_WITH_CHARTS | READ_DATA_ONLY | IGNORE_EMPTY_CELLS | IGNORE_ROWS_WITH_NO_CELLS |
1120+
|----------|------------------|----------------|--------------------|---------------------------|
1121+
| Xlsx | YES | YES | YES | YES |
1122+
| Xls | NO | YES | YES | NO |
1123+
| Xml | NO | NO | NO | NO |
1124+
| Ods | NO | YES | NO | NO |
1125+
| Gnumeric | NO | YES | NO | NO |
1126+
| Html | N/A | N/A | N/A | N/A |
1127+
| Slk | N/A | NO | NO | NO |
1128+
| Csv | N/A | NO | NO | NO |
11291129

11301130
Likewise, when saving a file using a Writer, loaded charts will not be saved unless you explicitly tell the Writer to include them:
11311131

@@ -1162,5 +1162,5 @@ Two or more flags can be passed together using PHP's `|` operator.
11621162

11631163
```php
11641164
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile("myExampleFile.xlsx");
1165-
$reader->load("spreadsheetWithCharts.xlsx", $reader::READ_DATA_ONLY | $reader::SKIP_EMPTY_CELLS);
1165+
$reader->load("spreadsheetWithCharts.xlsx", $reader::READ_DATA_ONLY | $reader::IGNORE_EMPTY_CELLS);
11661166
```

src/PhpSpreadsheet/Reader/BaseReader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class BaseReader implements IReader
1919

2020
/**
2121
* Read empty cells?
22-
* Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing
22+
* Identifies whether the Reader should read data values for all cells, or should ignore cells containing
2323
* null value or empty string.
2424
*/
2525
protected bool $readEmptyCells = true;
@@ -166,7 +166,7 @@ protected function processFlags(int $flags): void
166166
if (((bool) ($flags & self::READ_DATA_ONLY)) === true) {
167167
$this->setReadDataOnly(true);
168168
}
169-
if (((bool) ($flags & self::SKIP_EMPTY_CELLS) || (bool) ($flags & self::IGNORE_EMPTY_CELLS)) === true) {
169+
if (((bool) ($flags & self::IGNORE_EMPTY_CELLS)) === true) {
170170
$this->setReadEmptyCells(false);
171171
}
172172
if (((bool) ($flags & self::IGNORE_ROWS_WITH_NO_CELLS)) === true) {

src/PhpSpreadsheet/Reader/IReader.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,36 @@
66

77
interface IReader
88
{
9+
/**
10+
* Flag used to load the charts.
11+
*
12+
* This flag is supported only for some formats.
13+
*/
914
public const LOAD_WITH_CHARTS = 1;
1015

16+
/**
17+
* Flag used to read data only, not style or structure information.
18+
*/
1119
public const READ_DATA_ONLY = 2;
1220

13-
public const SKIP_EMPTY_CELLS = 4;
21+
/**
22+
* @deprecated 3.4.0 use IGNORE_EMPTY_CELLS instead.
23+
*/
24+
public const SKIP_EMPTY_CELLS = self::IGNORE_EMPTY_CELLS;
25+
26+
/**
27+
* Flag used to ignore empty cells when reading.
28+
*
29+
* The ignored cells will not be instantiated.
30+
*/
1431
public const IGNORE_EMPTY_CELLS = 4;
1532

33+
/**
34+
* Flag used to ignore rows without cells.
35+
*
36+
* This flag is supported only for some formats.
37+
* This can heavily improve performance for some files.
38+
*/
1639
public const IGNORE_ROWS_WITH_NO_CELLS = 8;
1740

1841
public function __construct();
@@ -119,7 +142,7 @@ public function setReadFilter(IReadFilter $readFilter): self;
119142
* @param int $flags Flags that can change the behaviour of the Writer:
120143
* self::LOAD_WITH_CHARTS Load any charts that are defined (if the Reader supports Charts)
121144
* self::READ_DATA_ONLY Read only data, not style or structure information, from the file
122-
* self::SKIP_EMPTY_CELLS Don't read empty cells (cells that contain a null value,
145+
* self::IGNORE_EMPTY_CELLS Don't read empty cells (cells that contain a null value,
123146
* empty string, or a string containing only whitespace characters)
124147
*/
125148
public function load(string $filename, int $flags = 0): Spreadsheet;

0 commit comments

Comments
 (0)