Open MohiniLimbodia opened 5 years ago
Also getting this. Openpyxl detects illegal characters with the following regex:
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
I'm using django-import-export, which in turn uses tablib, which uses openpyxl. Still trying to figure out who should handle the data cleaning.
I fixed the issue by cleaning the data before it gets sent to tablib.
If anyone else is having this issue with django-import-export, you can clean your fields by overriding export_field on your resource.
from import_export import resources
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
class CleanModelResource(resources.ModelResource):
def export_field(self, field, obj):
v = super(CleanModelResource, self).export_field(field, obj)
if type(v) == str:
v = ILLEGAL_CHARACTERS_RE.sub('', v)
return v
Using tablib version 0.13.0 The issue is with Control Characters and Surrogates
Steps to reproduce:
Stack Trace