Bug 150229 - Links in cells truncated when saved/re-opened (XLSX format)
Summary: Links in cells truncated when saved/re-opened (XLSX format)
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.3.4.2 release
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:26.2.0 target:25.8.1
Keywords: filter:xlsx
Depends on:
Blocks: XLSX-Hyperlink
  Show dependency treegraph
 
Reported: 2022-08-01 21:41 UTC by jjgurley
Modified: 2025-08-24 19:27 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Simple test case (5.99 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2022-08-01 21:41 UTC, jjgurley
Details
XLSX with 8192-character hyperlink (8.97 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2025-08-22 14:09 UTC, Mike Kaganski
Details
XLS with 2083-character hyperlink (30.00 KB, application/vnd.ms-excel)
2025-08-22 14:11 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jjgurley 2022-08-01 21:41:19 UTC
Created attachment 181540 [details]
Simple test case

If you create a rather long link (I happen to be creating multiple destination routes in Google Maps and add them to a cell (via CTRL+K), they work as expected until you save and re-open the file as XLSX.  It works properly if you use ODS.

For example, if a link is 300 characters, it gets truncated to 'about' 256 characters.  I get variable lengths, but always in the 256 ballpark, so there's probably something to do with the specific string contents.

I've attached a two cell sheet.  Just copy the link contained in A1 using CTRL+K after selecting A2.  Close, re-open, voila.

1) open LINKS.XLSX
2) select cell A1, hit CTRL+C
3) select cell A2, highlight "LINKS"
4) hit CTRL+K, hit CTRL+V, close
5) CTRL+leftclick to go to link in browser
6) Save/Close/reopen and try #5 again.
Comment 2 Eike Rathke 2022-08-03 21:57:12 UTC
All those XclExpString instances that truncate to 255 probably need to distinguish between BIFF and OOXML export and truncate only for BIFF. Just guessing, untested. (if OOXML actually allows longer strings in that context).
Comment 3 jjgurley 2022-08-03 22:30:45 UTC
There is a work-around:

In the provided example

a2 = hyperlink(a1;"text")

allows an offsheet or hidden cell to contain the link in plain text, which doesn't get truncated.
Comment 4 Mike Kaganski 2022-08-04 05:29:59 UTC
(In reply to Eike Rathke from comment #2)

I can't tell if this is applicable (or if my test shows Excel storing those strings in a different internal structure, and thus comparing apples to oranges?), but MS Excel 2016 allows storing that long URLs also in XLS. So at least in this case, a *possible* fix could be to just increase the limit for all uses.
Comment 5 Mike Kaganski 2022-08-04 06:09:58 UTC
(In reply to Mike Kaganski from comment #4)

On the other hand: I tried to *create* such a link in Excel manually. I created an artificial URL of 2 700 000 characters (hoping that it would either show "there's no practical limit", or cut it down to an acceptable limit), and pasted into Excel's Ctrl+K hyperlink dialog.

The result was "The address for this hyperlink exceeds the 255-character limit. Please reduce the number of characters."

The message is indeed misleading, likely showing that Excel had such a limit at some point (95?), and didn't update error messages since increasing it. And the actual limit seems to be strange 2083 characters in the URL (it starts to show that dialog at 2084 characters).

Note that the testing was done with the default-created new Excel document, not with an XLS (legacy format), where some additional limitations could apply, nor with any "compatibility mode".
Comment 6 Mike Kaganski 2022-08-04 06:25:11 UTC
... and for XLS 97-2003, the actual limit (after which silent loss of hyperlink happens at save) is weird 1987 characters (1988 is lost).
Comment 7 Mike Kaganski 2022-08-04 06:30:40 UTC
And finally: for XLS 5.0-95, I couldn't persuade Excel 2016 to save even a short URL like https://example.org/.
Comment 8 Mike Kaganski 2025-08-22 06:57:20 UTC
(In reply to Mike Kaganski from comment #5)
> And the actual limit seems to be strange 2083 characters in the URL (it
> starts to show that dialog at 2084 characters).
> 
> Note that the testing was done with the default-created new Excel document,
> not with an XLS (legacy format), where some additional limitations could
> apply, nor with any "compatibility mode".

It looks strange now to me, after accidentally revisiting this due to https://ask.libreoffice.org/t/hyperlink-truncation-problem/125638 ; and testing now, I see the limit of 8192 characters in the URL for XLSX.
Comment 9 Mike Kaganski 2025-08-22 14:09:57 UTC
Created attachment 202450 [details]
XLSX with 8192-character hyperlink
Comment 10 Mike Kaganski 2025-08-22 14:11:03 UTC
Created attachment 202451 [details]
XLS with 2083-character hyperlink
Comment 11 Vladimir Sokolinskiy 2025-08-22 14:45:50 UTC
On my MS Excel 2016 (16.0.5513.1000) configuration:

1. File hyperlink2083ch.xls.

The file opens normally.

The hyperlink opens normally. When trying to change the hyperlink, a message (localized) appears:

"The hyperlink address is longer than 255 characters. Reduce the number of characters."

2. File hyperlink8192ch.xlsx

When opening, a message is displayed about the file structure being damaged. After restoration, the hyperlink length is 2084 characters.

The situation with editing the hyperlink is the same as with the previous file.
Comment 12 Vladimir Sokolinskiy 2025-08-22 15:02:12 UTC
Maybe (if it's not too much work) add a Parameter containing the maximum length of a hyperlink when exporting to MS Excel format (0 - do not shorten hyperlinks)?
Comment 13 Mike Kaganski 2025-08-22 16:41:16 UTC
https://gerrit.libreoffice.org/c/core/+/190078
Comment 14 Commit Notification 2025-08-22 19:31:12 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/f41c58ad4172729a2be261f0ccea01d741d61a2d

tdf#150229: increase maximum size of URLs for Excel file formats export

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Mike Kaganski 2025-08-23 11:13:37 UTC
(In reply to Vladimir Sokolinskiy from comment #12)
> add a Parameter containing the maximum length of a hyperlink when exporting to
> MS Excel format

No. We must not add parameters for infinite flexibility; we must not add parameters "let user play with external file format, because we are unsure", etc.

The fix hardcodes the known constants of limits. If a better knowledge appears, we will adjust them.
Comment 16 Commit Notification 2025-08-24 19:27:33 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-25-8":

https://git.libreoffice.org/core/commit/8013104ecc2e1a297cb238024c9a6100b07ff84d

tdf#150229: increase maximum size of URLs for Excel file formats export

It will be available in 25.8.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.