Bug Hunting Session
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: NEW
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: 2019-04-04 15:15 UTC (History)
9 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 stragu 2014-11-24 01:57:11 UTC
This is getting very confusing:

I just tested this in LO 4.3.3.2 on Ubuntu 14.04:

1. Insert hyperling to document in cell A1 in new spreadsheet
2. Save either in ods, xls or xlsx
3. Move the linked document to a diffent folder

None of the three formats updated the path, even though the box for "Save URLs relative to file system" is ticked!
Comment 7 QA Administrators 2015-12-20 16:01:09 UTC Comment hidden (obsolete)
Comment 8 stragu 2015-12-24 06:35:59 UTC
I am using the following:

Version: 5.0.3.2
Build ID: 1:5.0.3~rc2-0ubuntu1~trusty2
Locale: en-GB (en_GB.UTF-8)

I can't get Calc or Writer to update any hyperlink to a linked file that was moved.

I am using "Save URLs relative to file system" in the LO options, and I follow the following steps:

1. insert a hyperlink to a file (ctrl + K > document > document path)
2. save the document
3. move the linked file to a different folder
4. open the document: path to linked file was not updated

I have tried with different formats, both with Writer and Calc, and the link never updates.

I'm not even sure of what we are talking about here. Are the links even supposed to update when the linked file is moved?
Comment 9 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