33namespace PhpOffice \PhpSpreadsheet \Reader ;
44
55use PhpOffice \PhpSpreadsheet \Cell \Coordinate ;
6+ use PhpOffice \PhpSpreadsheet \Cell \Hyperlink ;
67use PhpOffice \PhpSpreadsheet \Document \Properties ;
78use PhpOffice \PhpSpreadsheet \NamedRange ;
89use PhpOffice \PhpSpreadsheet \Reader \Xlsx \Chart ;
@@ -1669,9 +1670,12 @@ public function load($pFilename)
16691670 Settings::getLibXmlLoaderOptions ()
16701671 );
16711672 $ images = [];
1672-
1673+ $ hyperlinks = [];
16731674 if ($ relsDrawing && $ relsDrawing ->Relationship ) {
16741675 foreach ($ relsDrawing ->Relationship as $ ele ) {
1676+ if ($ ele ['Type ' ] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink ' ) {
1677+ $ hyperlinks [(string ) $ ele ['Id ' ]] = (string ) $ ele ['Target ' ];
1678+ }
16751679 if ($ ele ['Type ' ] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image ' ) {
16761680 $ images [(string ) $ ele ['Id ' ]] = self ::dirAdd ($ fileDrawing , $ ele ['Target ' ]);
16771681 } elseif ($ ele ['Type ' ] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart ' ) {
@@ -1699,6 +1703,9 @@ public function load($pFilename)
16991703 $ xfrm = $ oneCellAnchor ->pic ->spPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->xfrm ;
17001704 /** @var SimpleXMLElement $outerShdw */
17011705 $ outerShdw = $ oneCellAnchor ->pic ->spPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->effectLst ->outerShdw ;
1706+ /** @var \SimpleXMLElement $hlinkClick */
1707+ $ hlinkClick = $ oneCellAnchor ->pic ->nvPicPr ->cNvPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->hlinkClick ;
1708+
17021709 $ objDrawing = new \PhpOffice \PhpSpreadsheet \Worksheet \Drawing ();
17031710 $ objDrawing ->setName ((string ) self ::getArrayItem ($ oneCellAnchor ->pic ->nvPicPr ->cNvPr ->attributes (), 'name ' ));
17041711 $ objDrawing ->setDescription ((string ) self ::getArrayItem ($ oneCellAnchor ->pic ->nvPicPr ->cNvPr ->attributes (), 'descr ' ));
@@ -1729,6 +1736,9 @@ public function load($pFilename)
17291736 $ shadow ->getColor ()->setRGB (self ::getArrayItem ($ outerShdw ->srgbClr ->attributes (), 'val ' ));
17301737 $ shadow ->setAlpha (self ::getArrayItem ($ outerShdw ->srgbClr ->alpha ->attributes (), 'val ' ) / 1000 );
17311738 }
1739+
1740+ $ this ->readHyperLinkDrawing ($ objDrawing , $ oneCellAnchor , $ hyperlinks );
1741+
17321742 $ objDrawing ->setWorksheet ($ docSheet );
17331743 } else {
17341744 // ? Can charts be positioned with a oneCellAnchor ?
@@ -1746,6 +1756,7 @@ public function load($pFilename)
17461756 $ blip = $ twoCellAnchor ->pic ->blipFill ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->blip ;
17471757 $ xfrm = $ twoCellAnchor ->pic ->spPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->xfrm ;
17481758 $ outerShdw = $ twoCellAnchor ->pic ->spPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->effectLst ->outerShdw ;
1759+ $ hlinkClick = $ twoCellAnchor ->pic ->nvPicPr ->cNvPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->hlinkClick ;
17491760 $ objDrawing = new \PhpOffice \PhpSpreadsheet \Worksheet \Drawing ();
17501761 $ objDrawing ->setName ((string ) self ::getArrayItem ($ twoCellAnchor ->pic ->nvPicPr ->cNvPr ->attributes (), 'name ' ));
17511762 $ objDrawing ->setDescription ((string ) self ::getArrayItem ($ twoCellAnchor ->pic ->nvPicPr ->cNvPr ->attributes (), 'descr ' ));
@@ -1777,6 +1788,9 @@ public function load($pFilename)
17771788 $ shadow ->getColor ()->setRGB (self ::getArrayItem ($ outerShdw ->srgbClr ->attributes (), 'val ' ));
17781789 $ shadow ->setAlpha (self ::getArrayItem ($ outerShdw ->srgbClr ->alpha ->attributes (), 'val ' ) / 1000 );
17791790 }
1791+
1792+ $ this ->readHyperLinkDrawing ($ objDrawing , $ twoCellAnchor , $ hyperlinks );
1793+
17801794 $ objDrawing ->setWorksheet ($ docSheet );
17811795 } elseif (($ this ->includeCharts ) && ($ twoCellAnchor ->graphicFrame )) {
17821796 $ fromCoordinate = Coordinate::stringFromColumnIndex (((string ) $ twoCellAnchor ->from ->col ) + 1 ) . ($ twoCellAnchor ->from ->row + 1 );
@@ -2427,6 +2441,27 @@ private static function boolean($value)
24272441 return $ value === 'true ' || $ value === 'TRUE ' ;
24282442 }
24292443
2444+ /**
2445+ * @param \PhpOffice\PhpSpreadsheet\Worksheet\Drawing $objDrawing
2446+ * @param \SimpleXMLElement $cellAnchor
2447+ * @param array $hyperlinks
2448+ */
2449+ private function readHyperLinkDrawing ($ objDrawing , $ cellAnchor , $ hyperlinks )
2450+ {
2451+ $ hlinkClick = $ cellAnchor ->pic ->nvPicPr ->cNvPr ->children ('http://schemas.openxmlformats.org/drawingml/2006/main ' )->hlinkClick ;
2452+
2453+ if ($ hlinkClick ->count () === 0 ) {
2454+ return ;
2455+ }
2456+
2457+ $ hlinkId = (string ) $ hlinkClick ->attributes ('http://schemas.openxmlformats.org/officeDocument/2006/relationships ' )['id ' ];
2458+ $ hyperlink = new Hyperlink (
2459+ $ hyperlinks [$ hlinkId ],
2460+ (string ) self ::getArrayItem ($ cellAnchor ->pic ->nvPicPr ->cNvPr ->attributes (), 'name ' )
2461+ );
2462+ $ objDrawing ->setHyperlink ($ hyperlink );
2463+ }
2464+
24302465 private function readProtection (Spreadsheet $ excel , SimpleXMLElement $ xmlWorkbook )
24312466 {
24322467 if (!$ xmlWorkbook ->workbookProtection ) {
0 commit comments