See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; 4 5 use PhpOffice\PhpSpreadsheet\Cell\Coordinate; 6 use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; 7 8 class Hyperlinks 9 { 10 private $worksheet; 11 12 private $hyperlinks = []; 13 14 public function __construct(Worksheet $workSheet) 15 { 16 $this->worksheet = $workSheet; 17 } 18 19 public function readHyperlinks(\SimpleXMLElement $relsWorksheet) 20 { 21 foreach ($relsWorksheet->Relationship as $element) { 22 if ($element['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { 23 $this->hyperlinks[(string) $element['Id']] = (string) $element['Target']; 24 } 25 } 26 } 27 28 public function setHyperlinks(\SimpleXMLElement $worksheetXml) 29 { 30 foreach ($worksheetXml->hyperlink as $hyperlink) { 31 $this->setHyperlink($hyperlink, $this->worksheet); 32 } 33 } 34 35 private function setHyperlink(\SimpleXMLElement $hyperlink, Worksheet $worksheet) 36 { 37 // Link url 38 $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); 39 40 foreach (Coordinate::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) { 41 $cell = $worksheet->getCell($cellReference); 42 if (isset($linkRel['id'])) { 43 $hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']]; 44 if (isset($hyperlink['location'])) { 45 $hyperlinkUrl .= '#' . (string) $hyperlink['location']; 46 } 47 $cell->getHyperlink()->setUrl($hyperlinkUrl); 48 } elseif (isset($hyperlink['location'])) { 49 $cell->getHyperlink()->setUrl('sheet://' . (string) $hyperlink['location']); 50 } 51 52 // Tooltip 53 if (isset($hyperlink['tooltip'])) { 54 $cell->getHyperlink()->setTooltip((string) $hyperlink['tooltip']); 55 } 56 } 57 } 58 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body