Few days ago I was informed about problems with the exported files of our forms, made with djangocms-forms. When you open the exported .xls
file with Microsoft Office Excel the following error message appears:
"We found a problem with some content in 'filename'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."
After clicking "Yes" the file opens but there are a lot of empty cells and others are filled with random unicode characters. The fields are required but just to ensure myself I exported the same data in csv and all cells were correctly filled. Same is the story with Libre Office.
I managed to reproduce the problem by submitting some not so common unicode characters. At first I had no idea where it comes from because there wasn't anything wrong with the code responsible for the export but after further investigation I located the error. I was suprised to find it not inside djangocms-forms but in tablib
, which is used for exporting. The problem is here:
https://github.com/kennethreitz/tablib/blob/master/tablib/formats/_xls.py#L136
I'm not opening an issue in tablib project because actually the problem is already reported there. There is an issue opened since September 2nd 2014 and it is still not solved. Maybe you can use another library for exporting .xls files or you can find a workaround. I tried using different version of tablib but without any success.
https://github.com/kennethreitz/tablib/issues/168
I couldn't find any specific character that causes the problem and it seems that it behaves differently when different set of data is already submitted. Despite that I always managed to reproduce it by just copying the content of this page, containing large set of all Unicode group of characters.
http://www.ltg.ed.ac.uk/~richard/unicode-sample.html
Create a simple form with at least one text field and submit it several times to have initial data to broke. Then paste the copied string.
There isn't anything special in my setup.
tablib==0.11.4
django-cms==3.3.3
djangocms-forms==0.2.4