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

writing urls with 2 '#' will raise ValueError: too many values to unpack #330

Closed
lismanb opened this Issue Jan 15, 2016 · 5 comments

Comments

2 participants
@lismanb

lismanb commented Jan 15, 2016

The issue is in worksheet.py in the write_url method, at this line "url, url_str = url.split('#')"

to reproduce:

import xlsxwriter
workbook = xlsxwriter.Workbook("whatever.xlsx")
worksheet = workbook.add_worksheet()
worksheet.write(0,0,"http://www.google.com/#string1#string2")

To fix it use this:

url,url_str = url.split('#',1)

Thanks

@jmcnamara jmcnamara added the question label Jan 15, 2016

@jmcnamara jmcnamara self-assigned this Jan 15, 2016

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jan 15, 2016

Owner

To fix it use this

That fixes the exception but it introduces another issue since Excel doesn't support urls with 2 # locations like this.

For example if you insert a url like http://www.google.com/foo#string1#string2 Excel truncates the url part to http://www.google.com/foo#string1 when you save the file and reopen it. The string/visible part remains the same.

Your example however http://www.google.com/#string1#string2 can be inserted in Excel as it is.

So duplicating Excel's behaviour here will be tricky.

Do you have an example of real urls like this in use?

Owner

jmcnamara commented Jan 15, 2016

To fix it use this

That fixes the exception but it introduces another issue since Excel doesn't support urls with 2 # locations like this.

For example if you insert a url like http://www.google.com/foo#string1#string2 Excel truncates the url part to http://www.google.com/foo#string1 when you save the file and reopen it. The string/visible part remains the same.

Your example however http://www.google.com/#string1#string2 can be inserted in Excel as it is.

So duplicating Excel's behaviour here will be tricky.

Do you have an example of real urls like this in use?

@jmcnamara jmcnamara added bug and removed question labels Jan 15, 2016

@lismanb

This comment has been minimized.

Show comment
Hide comment
@lismanb

lismanb Jan 15, 2016

unfortunately no, and I think it's not a valid url, but something like that came from an user.
And when I wanted to create the excel file with the user's input, it just complained about it.

But what I would like in this case is just to save the string , and not raise the exception.

lismanb commented Jan 15, 2016

unfortunately no, and I think it's not a valid url, but something like that came from an user.
And when I wanted to create the excel file with the user's input, it just complained about it.

But what I would like in this case is just to save the string , and not raise the exception.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jan 15, 2016

Owner

But what I would like in this case is just to save the string , and not raise the exception.

Ok. I can fix that.

But are you not bothered by the fact that if the user opens and then saves the file Excel will truncate the URL down to one # location?

Owner

jmcnamara commented Jan 15, 2016

But what I would like in this case is just to save the string , and not raise the exception.

Ok. I can fix that.

But are you not bothered by the fact that if the user opens and then saves the file Excel will truncate the URL down to one # location?

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jan 16, 2016

Owner

It looks like Excel only strips the second # anchor when the cell is edited and not just when the file is saved so that isn't as bad as I originally thought. Still it is a good indication that you probably shouldn't be adding invalid urls to an Excel worksheet.

Either way, I've fixed the exception and pushed the fix in version 0.8.4: https://xlsxwriter.readthedocs.org/changes.html

Owner

jmcnamara commented Jan 16, 2016

It looks like Excel only strips the second # anchor when the cell is edited and not just when the file is saved so that isn't as bad as I originally thought. Still it is a good indication that you probably shouldn't be adding invalid urls to an Excel worksheet.

Either way, I've fixed the exception and pushed the fix in version 0.8.4: https://xlsxwriter.readthedocs.org/changes.html

@jmcnamara jmcnamara closed this Jan 16, 2016

@lismanb

This comment has been minimized.

Show comment
Hide comment
@lismanb

lismanb Jan 18, 2016

Thanks a lot :)

lismanb commented Jan 18, 2016

Thanks a lot :)

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Jan 19, 2016

fhajny
Update textproc/py-xlsxwriter to 0.8.4.
Release 0.8.4 - January 16 2016
-------------------------------

* Fix for :func:`write_url` exception when the URL contains two ``#``
  location/anchors. Note, URLs like this aren't strictly valid and cannot be
  entered manually in Excel.
  Issue `#330 <https://github.com/jmcnamara/XlsxWriter/issues/330>`_.


Release 0.8.3 - January 14 2016
-------------------------------

* Added options to configure chart axis tick placement. See :func:`set_x_axis()`.


Release 0.8.2 - January 13 2016
-------------------------------

* Added transparency option to solid fill colors in chart areas
  (:ref:`chart_formatting_fill`).
  Feature request `#298 <https://github.com/jmcnamara/XlsxWriter/issues/298>`_.


Release 0.8.1 - January 12 2016
-------------------------------

* Added option to set chart tick interval.
  Feature request `#251 <https://github.com/jmcnamara/XlsxWriter/issues/251>`_.


Release 0.8.0 - January 10 2016
-------------------------------

* Added additional documentation on :ref:`working_with_formulas`.


Release 0.7.9 - January 9 2016
------------------------------

* Added chart pattern fills, see :ref:`chart_formatting_pattern` and
  :ref:`ex_chart_pattern`.
  Feature request `#268 <https://github.com/jmcnamara/XlsxWriter/issues/268>`_.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment