Closed
Description
When you set the content of a cell to =HYPERLINK("#anotherspreadshet!A1","link") the class throws the next Fatal error:
Uncaught exception 'PhpOffice\PhpSpreadsheet\Calculation\Exception' with message 'anotherspreadshet!A1 -> Formula Error: An unexpected error occured' in \src\PhpSpreadsheet\Cell.php:280
Stack trace:
#0 src\PhpSpreadsheet\Writer\Xlsx\Worksheet.php(1080): PhpOffice\PhpSpreadsheet\Cell->>getCalculatedValue()
#1 src\PhpSpreadsheet\Writer\Xlsx\Worksheet.php(1027): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet->writeCell(Object(PhpOffice\PhpSpreadsheet\Shared\XMLWriter), Object(PhpOffice\PhpSpreadsheet\Worksheet), 'A1', Array, Array)
#2 src\PhpSpreadsheet\Writer\Xlsx\Worksheet.php(80): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet->writeSheetData(Object(PhpOffice\PhpSpreadsheet\Shared\XMLWriter), Object(PhpOffice\PhpSpreadsheet\Worksheet), Array)
#3 srcl\PhpSpreadsheet\W src\Cell.php on line 280
Activity
[-]HYPERLINK function not working correctly when you try to link a cell on another spreadsheet[/-][+]HYPERLINK function not working correctly when you try to link a cell to another spreadsheet[/+]MarkBaker commentedon Dec 15, 2016
Nasty, nasty Microsoft.... they changed the syntax for inter-sheet references between formats.
For xls, the syntax is
sheet://anotherspreadshet!A1
; for xlsx, they changed it to#anotherspreadshet!A1
Will need to take a closer look at handling this, and it's made more awkward by using it in a formula
stale commentedon Dec 4, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.
oleibman commentedon Apr 30, 2025
Sometime between 7-odd years ago when this issue was marked stale and now, it was resolved. It happened so long ago that I can't even point to specific fix. Oddly, however, the issue was reported against Xlsx, and the commentary suggests that Xls was behaving. However, it seems to me that Xls is not working correctly, so I am reopening the issue, to be closed when I submit a PR to fix it, which I will do shortly.
Xls Writer Treat Hyperlink Starting with # as Internal