Refactor hyperlink URL assignment logic

Properly detect URLs with an anchor, like `https://example.com/#anchor` and don't convert them into an "internal" URL.
This commit is contained in:
Tobias Bäthge
2026-03-23 21:32:18 +01:00
committed by GitHub
parent eb391d1f22
commit c7f3ffba19
+13 -6
View File
@@ -44,13 +44,20 @@ class Hyperlinks
$attributes = Xlsx::getAttributes($hyperlink);
foreach (Coordinate::extractAllCellReferencesInRange($attributes->ref) as $cellReference) {
$cell = $worksheet->getCell($cellReference);
if (isset($attributes['location'])) {
$cell->getHyperlink()->setUrl('sheet://' . (string) $attributes['location']);
} elseif (isset($linkRel['id'])) {
$hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']] ?? '';
$cell->getHyperlink()->setUrl($hyperlinkUrl);
}
$hyperlinkUrl = '';
if (isset($linkRel['id'])) {
$hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']] ?? '';
}
if (isset($attributes['location'])) {
if ($hyperlinkUrl === '') {
$hyperlinkUrl = 'sheet://' . (string) $attributes['location'];
} else {
$hyperlinkUrl .= '#' . (string) $attributes['location'];
}
}
$cell->getHyperlink()->setUrl($hyperlinkUrl);
// Tooltip
if (isset($attributes['tooltip'])) {
$cell->getHyperlink()->setTooltip((string) $attributes['tooltip']);