@@ -3233,13 +3233,16 @@ public function rangeToArray(
3233
3233
$ maxRow = $ rangeEnd [1 ];
3234
3234
3235
3235
++$ maxCol ;
3236
+ $ nullRow = $ this ->buildNullRow ($ nullValue , $ minCol , $ maxCol , $ returnCellRef , $ ignoreHidden );
3237
+
3236
3238
// Loop through rows
3237
3239
$ r = -1 ;
3238
3240
for ($ row = $ minRow ; $ row <= $ maxRow ; ++$ row ) {
3239
3241
if (($ ignoreHidden === true ) && ($ this ->getRowDimension ($ row )->getVisible () === false )) {
3240
3242
continue ;
3241
3243
}
3242
3244
$ rowRef = $ returnCellRef ? $ row : ++$ r ;
3245
+ $ returnValue [$ rowRef ] = $ nullRow ;
3243
3246
$ c = -1 ;
3244
3247
// Loop through columns in the current row
3245
3248
for ($ col = $ minCol ; $ col !== $ maxCol ; ++$ col ) {
@@ -3250,7 +3253,6 @@ public function rangeToArray(
3250
3253
// Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
3251
3254
// so we test and retrieve directly against cellCollection
3252
3255
$ cell = $ this ->getCellCollection ()->get ("{$ col }{$ row }" );
3253
- $ returnValue [$ rowRef ][$ columnRef ] = $ nullValue ;
3254
3256
if ($ cell !== null ) {
3255
3257
$ returnValue [$ rowRef ][$ columnRef ] = $ this ->cellToArray ($ cell , $ calculateFormulas , $ formatData , $ nullValue );
3256
3258
}
@@ -3261,6 +3263,37 @@ public function rangeToArray(
3261
3263
return $ returnValue ;
3262
3264
}
3263
3265
3266
+ /**
3267
+ * Prepare a row data filled with null values to deduplicate the memory areas for empty rows.
3268
+ *
3269
+ * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist
3270
+ * @param string $minCol Start column of the range
3271
+ * @param string $maxCol End column of the range
3272
+ * @param bool $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
3273
+ * True - Return rows and columns indexed by their actual row and column IDs
3274
+ * @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
3275
+ * True - Don't return values for rows/columns that are defined as hidden.
3276
+ */
3277
+ private function buildNullRow (
3278
+ mixed $ nullValue ,
3279
+ string $ minCol ,
3280
+ string $ maxCol ,
3281
+ bool $ returnCellRef ,
3282
+ bool $ ignoreHidden ,
3283
+ ): array {
3284
+ $ nullRow = [];
3285
+ $ c = -1 ;
3286
+ for ($ col = $ minCol ; $ col !== $ maxCol ; ++$ col ) {
3287
+ if (($ ignoreHidden === true ) && ($ this ->getColumnDimension ($ col )->getVisible () === false )) {
3288
+ continue ;
3289
+ }
3290
+ $ columnRef = $ returnCellRef ? $ col : ++$ c ;
3291
+ $ nullRow [$ columnRef ] = $ nullValue ;
3292
+ }
3293
+
3294
+ return $ nullRow ;
3295
+ }
3296
+
3264
3297
private function validateNamedRange (string $ definedName , bool $ returnNullIfInvalid = false ): ?DefinedName
3265
3298
{
3266
3299
$ namedRange = DefinedName::resolveName ($ definedName , $ this );
0 commit comments