diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to '')
-rw-r--r-- | vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php new file mode 100644 index 0000000..697def3 --- /dev/null +++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php @@ -0,0 +1,59 @@ +<?php
+
+namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
+
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
+use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
+use SimpleXMLElement;
+
+class Hyperlinks
+{
+ private $worksheet;
+
+ private $hyperlinks = [];
+
+ public function __construct(Worksheet $workSheet)
+ {
+ $this->worksheet = $workSheet;
+ }
+
+ public function readHyperlinks(SimpleXMLElement $relsWorksheet): void
+ {
+ foreach ($relsWorksheet->Relationship as $element) {
+ if ($element['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') {
+ $this->hyperlinks[(string) $element['Id']] = (string) $element['Target'];
+ }
+ }
+ }
+
+ public function setHyperlinks(SimpleXMLElement $worksheetXml): void
+ {
+ foreach ($worksheetXml->hyperlink as $hyperlink) {
+ $this->setHyperlink($hyperlink, $this->worksheet);
+ }
+ }
+
+ private function setHyperlink(SimpleXMLElement $hyperlink, Worksheet $worksheet): void
+ {
+ // Link url
+ $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
+
+ foreach (Coordinate::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) {
+ $cell = $worksheet->getCell($cellReference);
+ if (isset($linkRel['id'])) {
+ $hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']];
+ if (isset($hyperlink['location'])) {
+ $hyperlinkUrl .= '#' . (string) $hyperlink['location'];
+ }
+ $cell->getHyperlink()->setUrl($hyperlinkUrl);
+ } elseif (isset($hyperlink['location'])) {
+ $cell->getHyperlink()->setUrl('sheet://' . (string) $hyperlink['location']);
+ }
+
+ // Tooltip
+ if (isset($hyperlink['tooltip'])) {
+ $cell->getHyperlink()->setTooltip((string) $hyperlink['tooltip']);
+ }
+ }
+ }
+}
|