Illegal characters in cells

465 views
Skip to first unread message

fi...@gruwier.dk

unread,
Aug 10, 2017, 8:01:48 AM8/10/17
to openpyxl-users
 A user of my application has problems generating Excel with OpenPyXL. Stacktrace shows that cell.py raises IllegalCharacterError. I can see from the code that there's a number of characters that are treated as 'illegal', including some rather common ones like space, exclamation mark and quotation mark. This is rather puzzling. How can space be an illegal character in a cell?

Charlie Clark

unread,
Aug 10, 2017, 8:04:11 AM8/10/17
to openpyx...@googlegroups.com
It's probably not a space but a non-visible control character. These are
excluded by the specification:

ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')

Best checking the ord() of the character.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

fi...@gruwier.dk

unread,
Aug 10, 2017, 8:18:50 AM8/10/17
to openpyxl-users
The problem is that I don't know which character causes the trouble...

Charlie Clark

unread,
Aug 10, 2017, 8:23:14 AM8/10/17
to openpyx...@googlegroups.com
Am .08.2017, 14:18 Uhr, schrieb <fi...@gruwier.dk>:

> The problem is that I don't know which character causes the trouble...

Get your user to check. You could monkey patch the code to include the
ASCII number in the exception and then submit a PR.

fi...@gruwier.dk

unread,
Aug 10, 2017, 10:36:58 AM8/10/17
to openpyxl-users
It turns out to be ASCII 11, 'vertical tab'.

How do I submit a PR? Maybe by creating an issue in Bitbucket?

Charlie Clark

unread,
Aug 10, 2017, 10:44:30 AM8/10/17
to openpyx...@googlegroups.com
Am .08.2017, 16:36 Uhr, schrieb <fi...@gruwier.dk>:

> It turns out to be ASCII 11, 'vertical tab'.
> How do I submit a PR? Maybe by creating an issue in Bitbucket?

It usually best to start with an issue as this provides the context.

The process for creating a PR (pull request) is the same for most
projects: create your own clone of the project, check it out locally,
write the relevant code, tests and documentation, pull the changes to your
clone and then submit a pull request from the Bitbucket UI.

Please refer the relevant part of the documentation and make sure you
switch to the relevant branch (2.4 in this case).

fi...@gruwier.dk

unread,
Aug 11, 2017, 4:29:48 AM8/11/17
to openpyxl-users
As I read the expression, Unicode value 11 is not an 'illegal character'. So how come that I get an exception for this value?

Charlie Clark

unread,
Aug 11, 2017, 5:06:24 AM8/11/17
to openpyx...@googlegroups.com
Am .08.2017, 10:29 Uhr, schrieb <fi...@gruwier.dk>:

> As I read the expression, Unicode value 11 is not an 'illegal character'.
> So how come that I get an exception for this value?

You can always check the tests for the regex. But it could simply be
another character that is causing the problems. You or your user are the
only ones who can really get to the bottom of this.

John Bovey

unread,
Aug 11, 2017, 5:40:58 AM8/11/17
to openpyx...@googlegroups.com
Vertical tab is 11 decimal or 013 octal so it would be matched by the regular expression.

John
--
Sent from my Android phone.

fi...@gruwier.dk

unread,
Aug 11, 2017, 6:58:28 AM8/11/17
to openpyxl-users, J.D....@kent.ac.uk
Thanks! I mistakingly assumed that the regex was in decimal notation. 
Reply all
Reply to author
Forward
0 new messages