@@ -46,10 +46,10 @@ particularly when working with large spreadsheets. One technique used to
46
46
reduce this memory overhead is cell caching, so cells are actually
47
47
maintained in a collection that may or may not be held in memory while you
48
48
are working with the spreadsheet. Because of this, a call to ` getCell() `
49
- (or any similar method) returns the cell data, and a pointer to the collection.
49
+ (or any similar method) returns the cell data, and sets a cell pointer to that cell in the collection.
50
50
While this is not normally an issue, it can become significant
51
51
if you assign the result of a call to ` getCell() ` to a variable. Any
52
- subsequent calls to retrieve other cells will unset that pointer, although
52
+ subsequent calls to retrieve other cells will change that pointer, although
53
53
the cell object will still retain its data values.
54
54
55
55
What does this mean? Consider the following code:
@@ -441,16 +441,25 @@ foreach ($worksheet->getRowIterator() as $row) {
441
441
echo '</table >' . PHP_EOL;
442
442
```
443
443
444
- Note that we have set the cell iterator's
445
- ` setIterateOnlyExistingCells() ` to FALSE. This makes the iterator loop
446
- all cells within the worksheet range, even if they have not been set.
447
-
448
- The cell iterator will return a ` null ` as the cell value if it is not
449
- set in the worksheet. Setting the cell iterator's
450
- ` setIterateOnlyExistingCells() ` to ` false ` will loop all cells in the
451
- worksheet that can be available at that moment. This will create new
452
- cells if required and increase memory usage! Only use it if it is
453
- intended to loop all cells that are possibly available.
444
+ Note that we have set the cell iterator's ` setIterateOnlyExistingCells() `
445
+ to FALSE. This makes the iterator loop all cells within the worksheet
446
+ range, even if they have not been set.
447
+
448
+ The cell iterator will create a new empty cell in the worksheet if it
449
+ doesn't exist; return a ` null ` as the cell value if it is not set in
450
+ the worksheet; although we can also tell it to return a null value
451
+ rather than returning a new empty cell.
452
+ Setting the cell iterator's ` setIterateOnlyExistingCells() ` to ` false `
453
+ will loop all cells in the worksheet that can be available at that
454
+ moment. If this is then set to create new cells if required, then it
455
+ will likely increase memory usage!
456
+ Only use it if it is intended to loop all cells that are possibly
457
+ available; otherwise use the option to return a null value if a cell
458
+ doesn't exist, or iterate only the cells that already exist.
459
+
460
+ It is also possible to call the Row object's ` isEmpty() ` method to
461
+ determine whether you need to instantiate the Cell Iterator for that
462
+ Row.
454
463
455
464
### Looping through cells using indexes
456
465
0 commit comments