@@ -854,6 +854,8 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
854854 }
855855
856856 // Read cell!
857+ $ useFormula = isset ($ c ->f )
858+ && ((string ) $ c ->f !== '' || (isset ($ c ->f ->attributes ()['t ' ]) && strtolower ((string ) $ c ->f ->attributes ()['t ' ]) === 'shared ' ));
857859 switch ($ cellDataType ) {
858860 case DataType::TYPE_STRING :
859861 if ((string ) $ c ->v != '' ) {
@@ -868,7 +870,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
868870
869871 break ;
870872 case DataType::TYPE_BOOL :
871- if (!isset ( $ c -> f ) || (( string ) $ c -> f ) === '' ) {
873+ if (!$ useFormula ) {
872874 if (isset ($ c ->v )) {
873875 $ value = self ::castToBoolean ($ c );
874876 } else {
@@ -883,16 +885,16 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
883885
884886 break ;
885887 case DataType::TYPE_STRING2 :
886- if (isset ( $ c -> f ) ) {
888+ if ($ useFormula ) {
887889 $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , 'castToString ' );
888890 self ::storeFormulaAttributes ($ c ->f , $ docSheet , $ r );
889891 } else {
890- $ value = self ::castToString ($ c );
892+ $ value = self ::castToString ($ c );
891893 }
892894
893895 break ;
894896 case DataType::TYPE_INLINE :
895- if (isset ( $ c -> f ) ) {
897+ if ($ useFormula ) {
896898 $ this ->castToFormula ($ c , $ r , $ cellDataType , $ value , $ calculatedValue , 'castToError ' );
897899 self ::storeFormulaAttributes ($ c ->f , $ docSheet , $ r );
898900 } else {
@@ -901,7 +903,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
901903
902904 break ;
903905 case DataType::TYPE_ERROR :
904- if (!isset ( $ c -> f ) ) {
906+ if (!$ useFormula ) {
905907 $ value = self ::castToError ($ c );
906908 } else {
907909 // Formula
@@ -916,7 +918,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
916918
917919 break ;
918920 default :
919- if (!isset ( $ c -> f ) ) {
921+ if (!$ useFormula ) {
920922 $ value = self ::castToString ($ c );
921923 if (is_numeric ($ value )) {
922924 $ value += 0 ;
0 commit comments