@@ -784,6 +784,19 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
784784
785785 $ charts = $ chartDetails = [];
786786
787+ // Add richData (contains relation of in-cell images)
788+ $ richData = [];
789+ $ relationsFileName = $ dir . '/richData/_rels/richValueRel.xml.rels ' ;
790+ if ($ zip ->locateName ($ relationsFileName )) {
791+ $ relsWorksheet = $ this ->loadZip ($ relationsFileName , Namespaces::RELATIONSHIPS );
792+ foreach ($ relsWorksheet ->Relationship as $ elex ) {
793+ $ ele = self ::getAttributes ($ elex );
794+ if ($ ele ['Type ' ] == Namespaces::IMAGE ) {
795+ $ richData ['image ' ][(string ) $ ele ['Id ' ]] = (string ) $ ele ['Target ' ];
796+ }
797+ }
798+ }
799+
787800 $ sheetCreated = false ;
788801 if ($ xmlWorkbookNS ->sheets ) {
789802 foreach ($ xmlWorkbookNS ->sheets ->sheet as $ eleSheet ) {
@@ -940,34 +953,28 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
940953
941954 break ;
942955 case DataType::TYPE_ERROR :
943- if (isset ($ cAttr ->vm )) {
944- $ cell = $ docSheet ->getCell ($ r );
945- if ($ cell ) {
946-
947- $ objDrawing = new \PhpOffice \PhpSpreadsheet \Worksheet \Drawing ();
948- $ objDrawing ->setName ('' );
949- $ objDrawing ->setDescription ('' );
950- $ imagePath = 'xl/media/image ' . $ cAttr ->vm . '.png ' ;
951- $ objDrawing ->setPath (
952- 'zip:// ' . File::realpath ($ filename ) . '# ' . $ imagePath ,
953- false ,
954- $ zip
955- );
956+ if (isset ($ cAttr ->vm ) && isset ($ richData ['image ' ]['rId ' . $ cAttr ->vm ]) && !$ useFormula ) {
957+ $ imagePath = $ dir . '/ ' . str_replace ('../ ' , '' , $ richData ['image ' ]['rId ' . $ cAttr ->vm ]);
958+ $ objDrawing = new \PhpOffice \PhpSpreadsheet \Worksheet \Drawing ();
959+ $ objDrawing ->setPath (
960+ 'zip:// ' . File::realpath ($ filename ) . '# ' . $ imagePath ,
961+ false ,
962+ $ zip
963+ );
956964
957- $ objDrawing ->setCoordinates ($ r );
958- $ objDrawing ->setOffsetX (0 );
959- $ objDrawing ->setOffsetY (0 );
960- $ objDrawing ->setResizeProportional (false );
961- $ objDrawing ->setWorksheet ($ docSheet );
962- }
965+ $ objDrawing ->setCoordinates ($ r );
966+ $ objDrawing ->setOffsetX (0 );
967+ $ objDrawing ->setOffsetY (0 );
968+ $ objDrawing ->setResizeProportional (false );
969+ $ objDrawing ->setWorksheet ($ docSheet );
963970
964971 $ value = $ objDrawing ;
965972 $ cellDataType = DATATYPE ::TYPE_NULL ;
966973 $ c ->t = DATATYPE ::TYPE_NULL ;
967974
968975 break ;
969976 }
970-
977+
971978 if (!$ useFormula ) {
972979 $ value = self ::castToError ($ c );
973980 } else {
0 commit comments