New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Add support to set the "Hyperlink base" document property #306
Comments
I had a work colleague report a bug that when he modified and saved an Excel file that I created using Xlsxwriter, all the hyperlinks that use absolute UNC paths turn into relative paths and the URL can no longer be opened by copying and pasting into Windows Explorer. Anyway, the issue appears to be fixed by setting the "Hyperlink base" to "C:", see here: |
The "Hyperlink base" is an extended property just like the "Company" and "Manager" properties. These two properties currently get set in app.py with the _write_manager and _write_company functions, which are called by _assemble_xml_file. The fix would be to add a _write_hyperlink_base function which gets called by _assemble_xml_file and does the same thing as _write_manager except it looks for a hyperlink_base key inside the properties dictionary. The qualified name for the "Hyperlink base" is "HyperlinkBase" which is the first parameter that gets passed into _xml_data_element, see here: |
Hi Andrew, Thanks for the breakdown. It seems like a reasonable feature request. I'll look into it.
Just so everything is clear, could you post a small example that demonstrates the issue. John |
I've pushed a fix for this to the master branch. You can test it when you get a chance. The interface is like this: workbook.set_properties({'hyperlink_base': 'C:\\'}) |
Example:
Open the file, right click and edit the hyperlink on cell A1. Note how the URL is exactly as specified "\unc\path\with spaces in the url\test.txt". Now modify the worksheet, save and close the file. Re-open the file and right click and edit the hyperlink on cell A1 again. The URL should be a relative path now and the spaces have been escaped with %20. |
I don't see this behaviour. An issue with the spaces in external urls was fixed in the last release (0.7.4) so it would be best to upgrade to that version to ensure that isn't causing the issue that you are seeing. Just to make sure, I created a fie in Excel 2007 with a link similar to the one in your example and wrote a comparison test (see commit 347b46e). The results are identical (apart from file metadata dates). So I don't see the issue here. Try the upgrade and let me know how you get on. John |
Hi Andrew, Thanks for the clarification. I've added the Regards, John |
Thanks, setting the hyperlink_base in 0.7.5 works as expected! |
As seen here:
https://xlsxwriter.readthedocs.org/_images/doc_properties.png
There is a "Hyperlink base" property which can be set but is not currently supported by Xlsxwriter.
The text was updated successfully, but these errors were encountered: