jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.59k stars 590 forks source link

"Invalid character / found in sheet title" during export to XLSX #489

Closed mpasternak closed 3 years ago

mpasternak commented 3 years ago

Hi there,

it looks like tablib could automatically replace some characters when exporting to XLS, what do you think? The problem occurs when I export a sheet with a slash inside its title:

  File "/Users/mpasternak/.virtualenvs/bpp/lib/python3.8/site-packages/tablib/formats/_xlsx.py", line 53, in export_book
    ws.title = dset.title if dset.title else 'Sheet%s' % (i)
  File "/Users/mpasternak/.virtualenvs/bpp/lib/python3.8/site-packages/openpyxl/workbook/child.py", line 93, in title
    raise ValueError(msg)
ValueError: Invalid character / found in sheet title

Devs, please let me know if this is desired and I'll think about a patch.

claudep commented 3 years ago

Would you suggest replacing invalid chars (INVALID_TITLE_REGEX = re.compile(r'[\\*?:/\[\]]') with underscores?

mpasternak commented 3 years ago

Seems legit. Optionally make the underscore configurable with something else.

claudep commented 3 years ago

Feel free to suggest a patch!

mpasternak commented 3 years ago

OK cool, PR coming soon