Bug 45435 - XSLX format breaks relative hyperlink path when document is moved (comment 9)
Summary: XSLX format breaks relative hyperlink path when document is moved (comment 9)
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
3.5.0 release
Hardware: All All
: high normal
Assignee: Not Assigned
URL:
Whiteboard: BSA
Keywords:
: 97509 (view as bug list)
Depends on:
Blocks: XLSX-Hyperlink Hyperlink-Calc
  Show dependency treegraph
 
Reported: 2012-01-31 03:42 UTC by Sergey Savko
Modified: 2022-09-19 13:10 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Savko 2012-01-31 03:42:14 UTC
Problem description: Don't correct save and open link in hyperlink, in all versions LibO

Steps to reproduce:
1. In LibO Calc -> Insert -> Hyperlink, in right window select "Document" and set path to PDF or JPG url (for me /home/user/Desktop/32.png) -> Apply -> Close  -> Save File in desktop folder.
2. Then I copy file from desktop folder in document folder in my profile.
3. When I open the document and see the hyperlink path, I see /home/user/Desktop/Documents/32.png

Current behavior: Don't open file from hyperlink if file is copy in other folder.

Expected behavior: Should open the link.

Platform (if different from the browser): 
Kubuntu 8.04, 10.04;
Browser: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.15 (KHTML, like Gecko) Ubuntu/10.04 Chromium/18.0.996.0 Chrome/18.0.996.0 Safari/535.15
Comment 1 rpr 2012-03-03 06:45:35 UTC
This is not a bug actually as LibreOffice has the following option enabled by
default:
Tools -> Options -> Load/Save -> General -> Save URLs relative to file system

When you use Insert -> Hyperlink to create a hyperlink to a file in the file
system, Calc saves a relative path from the document to the linked file.

For example, if you are editing /home/user/Desktop/test.ods
and insert a hyperlink to /home/user/Desktop/a.pdf
Calc internally saves the following path: ../a.pdf
(ODS is actually a ZIP archive. You can copy test.ods to test.zip and then open
in with an archiver. There is the content.xml file inside the archive in which
you can see the "../a.pdf" path.)

If you move the spreadsheet to /home/user/Documents/test.ods
the hyperlink now links to /home/user/Documents/a.pdf
(/home/user/Documents/test.ods + ../a.pdf = /home/user/Documents/a.pdf)
although the text shown in the cell still reads /home/user/Desktop/a.pdf
which can be corrected by Insert -> Hyperlink.

This behaviour can be very useful if you have a set of linked files and move
them as a group keeping their relative positions in the file system. If you
want that hyperlinks use absolute paths then disable the following option:
Tools -> Options -> Load/Save -> General -> Save URLs relative to file system

I've tested this in LibO Calc 3.5.0 on Ubuntu 11.10.
Comment 2 Sergey Savko 2012-03-06 06:49:10 UTC
Hmm, you right. In version 3.3.4 it does not work, in 3.5.0 work fine.
Thank you very much
Comment 3 Sergey Savko 2012-03-29 07:09:25 UTC
LibreOffice 3.5.1.
So, if i save in ods it's works. If i'm save file in xls, hyperlinks is wrong.
Comment 4 ign_christian 2013-06-29 02:56:47 UTC
Hi Sergey, is it still happen on latest stable release?
Comment 5 Thomas Arnhold 2013-10-16 17:29:16 UTC
Reproduced on Windows 7 with:

Version: 4.1.2.3
Build ID: 40b2d7fde7e8d2d7bc5a449dc65df4d08a7dd38

When saving as XLS or XSLX and moving the file afterwards the link is broken.
Comment 6 Stéphane Guillou (stragu) 2014-11-24 01:57:11 UTC Comment hidden (obsolete)
Comment 7 QA Administrators 2015-12-20 16:01:09 UTC Comment hidden (obsolete)
Comment 8 Stéphane Guillou (stragu) 2015-12-24 06:35:59 UTC Comment hidden (obsolete)
Comment 9 Stéphane Guillou (stragu) 2015-12-24 07:07:00 UTC
OK I think I see what the original author means.

1. create a new document in Calc
2. make sure the option "Save URLs relative to file system" is ticked in "options > save/load > general"
3. add a hyperlink to any file in the same folder as the document, with "ctrl + k > document", set the path to the file and click "OK"
4. save the document as xlsx and close the document
5. move the document and the linked file together in a different folder
6. open the document and try to open the linked file via the hyperlink (ctrl + right click)

Expected behaviour: the relative path allows to open the linked file.

Actual behaviour: the linked filed can not be opened (the path is "/<filename>", with error message "<filepath> does not exist").

The behaviour is as expected if the spreadsheet is saved as odt or xls.

Tested with:
Version: 5.0.3.2
Build ID: 1:5.0.3~rc2-0ubuntu1~trusty2
Locale: en-GB (en_GB.UTF-8)
Comment 10 Sergey Savko 2016-01-11 10:49:04 UTC
1. create a new document in Calc
2. make sure the option "Save URLs relative to file system" is ticked in "options > save/load > general"
3. add a hyperlink to any file in the same folder as the document, with "ctrl + k > document", set the path to the file and click "OK"
4. save the document as xlsx and close the document
5. move the document and the linked file together in a different folder
6. open the document and try to open the linked file via the hyperlink (ctrl + right click)

Yes, you are right.

I copied only xlsx file. I did not copy the picture.
If only xlsx file was copied, we would have an error message that the linked file could not be open.

You can close this bug because i did not know the "Save URLs relative to file system" option.
Comment 11 Sašo Smolej 2016-02-02 16:02:43 UTC
*** Bug 97509 has been marked as a duplicate of this bug. ***
Comment 12 Sašo Smolej 2016-02-02 16:19:06 UTC
While this page shed some light on my bug report (marked as duplicate), I disagree with how the feature works. The full path is displayed to the user, which misleads just about anyone into thinking the path is absolute.

Now I understand the argument of using relative paths, especially if the images are linked to reduce file size and are generally in the same folder or subfolder as the main document - therefore part of that specific project.

But I will argue the opposite: To avoid data duplication and enable simpler editing of images in multiple documents (such as perhaps company logos or some information that is generally the same), those images are generally saved in a specific place relative to the drive/computer, not the document.



I would suggest the following solution: support both and determine which one to use on the fly (or let user decide):
1) For images that are in the same folder or in a subfolder of the main document, use relative paths.
2) For images that are in a different path altogether - requiring use of "../" - use absolute paths.

Assuming the above, a document with the path "Z:\Header\Somethingspecific\stuff.ods"
and linked images
Z:\Header\Somethingspecific\images\something.jpg
Z:\Header\header.jpg

For option 1, paths should be saved and displayed as "\images\something.jpg", assuming it's something that concerns more or less just that document.

For option 2, paths should be saved and displayed as "Z:\Header\header.png".


My biggest gripe with this is that even if you use relative paths, the absolute path is displayed in the menu, which is misleading and confusing at best - in the very least change the way it's displayed.
Comment 13 Justin L 2018-02-20 19:12:44 UTC
confirmed that "save URLs relative to file system" exists in the oldest bibisect I can run in 16.04, so assume inherited from OOo.
Frustratingly, I couldn't even find a code point to grab a hold of for the display of the URL string. Code pointer needed.
Comment 14 Justin L 2018-02-22 18:20:41 UTC
Google suggests that Microsoft doesn't support relative paths well in .xlsx. So that may be why .xlsx uses non-relative paths.

Code pointers: include/editeng/flditems.hxx SvxURLField::GetRepresentation()
and the corresponding editeng/source/items/flditems.cxx
Comment 15 Justin L 2018-02-23 11:23:12 UTC
Code pointers for the displayed path (comment 12's gripe):
-saving as .ods:  sc/source/filter/xml/xmlexport.cxx writeContent() aFieldVal
-saving as .xls:  sc/source/filter/excel/xecontent.cxx XclExpHyperlink rRepr
-saving as .xlsx: sc/source/filter/excel/xecontent.cxx SaveXml() m_Repr
Comment 16 QA Administrators 2022-09-16 03:39:49 UTC Comment hidden (obsolete)
Comment 17 Stéphane Guillou (stragu) 2022-09-17 20:41:51 UTC
Using steps in comment 9, I can reproduce the bug in:

Version: 6.3.6.2
Build ID: 2196df99b074d8a661f4036fca8fa0cbfa33a497
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3; 
Locale: en-AU (en_AU.UTF-8); UI-Language: en-US
Calc: threaded

But it works as expected since at least:

Version: 6.4.7.2
Build ID: 1:6.4.7-0ubuntu0.20.04.4
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3; 
Locale: en-AU (en_AU.UTF-8); UI-Language: en-US
Calc: threaded

Marking as "works for me".
Comment 18 Susan Cragin 2022-09-19 13:09:48 UTC
Works for me with an Office master spreadsheet and my LO additions. 
I have LO 7.3.6.2.
Comment 19 Susan Cragin 2022-09-19 13:10:10 UTC Comment hidden (obsolete)