mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 20:49:55 +00:00
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:
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user