@@ -307,28 +307,34 @@ private static function castToString($c)
307
307
return isset ($ c ->v ) ? (string ) $ c ->v : null ;
308
308
}
309
309
310
- private function castToFormula ($ c , $ r , &$ cellDataType , &$ value , &$ calculatedValue , &$ sharedFormulas , $ castBaseType ): void
310
+ private function castToFormula (Worksheet $ docSheet , $ c , $ r , &$ cellDataType , &$ value , &$ calculatedValue , &$ sharedFormulas , $ castBaseType ): void
311
311
{
312
- $ attr = $ c ->f ->attributes ();
312
+ $ formulaAttributes = $ c ->f ->attributes ();
313
313
$ cellDataType = 'f ' ;
314
314
$ value = "= {$ c ->f }" ;
315
315
$ calculatedValue = self ::$ castBaseType ($ c );
316
316
317
317
// Shared formula?
318
- if (isset ($ attr ['t ' ]) && strtolower ((string ) $ attr ['t ' ]) == 'shared ' ) {
319
- $ instance = (string ) $ attr ['si ' ];
318
+ if (isset ($ formulaAttributes ['t ' ])) {
319
+ if (strtolower ((string ) $ formulaAttributes ['t ' ]) === 'shared ' ) {
320
+ $ instance = (string ) $ formulaAttributes ['si ' ];
320
321
321
- if (!isset ($ sharedFormulas [(string ) $ attr ['si ' ]])) {
322
- $ sharedFormulas [$ instance ] = ['master ' => $ r , 'formula ' => $ value ];
323
- } else {
324
- $ master = Coordinate::indexesFromString ($ sharedFormulas [$ instance ]['master ' ]);
325
- $ current = Coordinate::indexesFromString ($ r );
322
+ if (!isset ($ sharedFormulas [(string ) $ formulaAttributes ['si ' ]])) {
323
+ $ sharedFormulas [$ instance ] = ['master ' => $ r , 'formula ' => $ value ];
324
+ } else {
325
+ $ master = Coordinate::indexesFromString ($ sharedFormulas [$ instance ]['master ' ]);
326
+ $ current = Coordinate::indexesFromString ($ r );
326
327
327
- $ difference = [0 , 0 ];
328
- $ difference [0 ] = $ current [0 ] - $ master [0 ];
329
- $ difference [1 ] = $ current [1 ] - $ master [1 ];
328
+ $ difference = [0 , 0 ];
329
+ $ difference [0 ] = $ current [0 ] - $ master [0 ];
330
+ $ difference [1 ] = $ current [1 ] - $ master [1 ];
330
331
331
- $ value = $ this ->referenceHelper ->updateFormulaReferences ($ sharedFormulas [$ instance ]['formula ' ], 'A1 ' , $ difference [0 ], $ difference [1 ]);
332
+ $ value = $ this ->referenceHelper ->updateFormulaReferences ($ sharedFormulas [$ instance ]['formula ' ], 'A1 ' , $ difference [0 ], $ difference [1 ]);
333
+ }
334
+ } elseif (strtolower ((string ) $ formulaAttributes ['t ' ]) === 'array ' ) {
335
+ $ formulaType = (string ) $ formulaAttributes ['t ' ];
336
+ $ formulaRange = $ formulaAttributes ['ref ' ] ? (string ) $ formulaAttributes ['ref ' ] : null ;
337
+ $ docSheet ->getCell ($ r )->setFormulaAttributes (['t ' => $ formulaType , 'ref ' => $ formulaRange ]);
332
338
}
333
339
}
334
340
}
@@ -747,7 +753,7 @@ public function load(string $filename, int $flags = 0): Spreadsheet
747
753
748
754
if (!$ this ->getReadFilter ()->readCell ($ coordinates [0 ], (int ) $ coordinates [1 ], $ docSheet ->getTitle ())) {
749
755
if (isset ($ cAttr ->f )) {
750
- $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
756
+ $ this ->castToFormula ($ docSheet , $ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
751
757
}
752
758
++$ rowIndex ;
753
759
@@ -779,17 +785,13 @@ public function load(string $filename, int $flags = 0): Spreadsheet
779
785
}
780
786
} else {
781
787
// Formula
782
- $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToBoolean ' );
783
- if (isset ($ c ->f ['t ' ])) {
784
- $ att = $ c ->f ;
785
- $ docSheet ->getCell ($ r )->setFormulaAttributes ($ att );
786
- }
788
+ $ this ->castToFormula ($ docSheet , $ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToBoolean ' );
787
789
}
788
790
789
791
break ;
790
792
case 'inlineStr ' :
791
793
if (isset ($ c ->f )) {
792
- $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
794
+ $ this ->castToFormula ($ docSheet , $ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
793
795
} else {
794
796
$ value = $ this ->parseRichText ($ c ->is );
795
797
}
@@ -800,7 +802,7 @@ public function load(string $filename, int $flags = 0): Spreadsheet
800
802
$ value = self ::castToError ($ c );
801
803
} else {
802
804
// Formula
803
- $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
805
+ $ this ->castToFormula ($ docSheet , $ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToError ' );
804
806
}
805
807
806
808
break ;
@@ -809,13 +811,7 @@ public function load(string $filename, int $flags = 0): Spreadsheet
809
811
$ value = self ::castToString ($ c );
810
812
} else {
811
813
// Formula
812
- $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToString ' );
813
- $ formulaAttributes = $ c ->f ->attributes ();
814
- if (isset ($ formulaAttributes ['t ' ])) {
815
- $ formulaType = $ formulaAttributes ['t ' ];
816
- $ formulaRange = $ formulaAttributes ['ref ' ] ? (string ) $ formulaAttributes ['ref ' ] : null ;
817
- $ docSheet ->getCell ($ r )->setFormulaAttributes (['t ' => (string ) $ formulaType , 'ref ' => $ formulaRange ]);
818
- }
814
+ $ this ->castToFormula ($ docSheet , $ c , $ r , $ cellDataType , $ value , $ calculatedValue , $ sharedFormulas , 'castToString ' );
819
815
}
820
816
821
817
break ;
0 commit comments