Skip to content
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

ODS exports numbers as text? #527

Closed
matthijskooijman opened this issue Oct 30, 2022 · 4 comments
Closed

ODS exports numbers as text? #527

matthijskooijman opened this issue Oct 30, 2022 · 4 comments

Comments

@matthijskooijman
Copy link

I've been trying to export data with numbers in them, and found I could not do calculations with them in the resulting ODS spreadsheet (the values are left-aligned instead of right aligned, and have a ' in front of them).

Here's my testcase:

data = tablib.Dataset()
data.append((1, 2.1))
f = open('tmp.ods', 'w')
f.write(data.ods)

Opening the resulting ODS in libreoffice shows:

image

Note the leading ' in the field value. I suspect that this leading ' is not written by tablib itself, but tablib writes out table cells as text. Here's a snippet from content.xml in the generated ODS:

<table:table-cell><text:p>1</text:p></table:table-cell><table:table-cell><text:p>2.1</text:p></table:table-cell>

The above screenshot is with the libreoffice locale set to "English (USA)". I originallly had it set to "Dutch (Netherlands)", which uses , as the decimal separator, so I suspected it was a decimal separator problem, but switching to a local with . as the decimal separator did not help.

Exporting in the xlsx format does give a proper numerical value that can be used in calculations (with both locales), so I'll be using that as a workaround for now.

claudep added a commit to claudep/tablib that referenced this issue Oct 30, 2022
claudep added a commit to claudep/tablib that referenced this issue Oct 30, 2022
@claudep
Copy link
Contributor

claudep commented Oct 30, 2022

I would appreciate if you could test my pull request.

claudep added a commit to claudep/tablib that referenced this issue Oct 31, 2022
Thanks Matthijs Kooijman for the report.
claudep added a commit to claudep/tablib that referenced this issue Oct 31, 2022
Thanks Matthijs Kooijman for the report.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
@hugovk hugovk closed this as completed in 3617859 Oct 31, 2022
@jrecasens
Copy link

jrecasens commented Jan 7, 2023

@claudep Would you please also add support for excel?

xlsx and xls export_type also exports numbers as text:

tablib excel issue

@matthijskooijman
Copy link
Author

xlsx and xls export_type also exports numbers as text:

Are you sure? I believe I switched from ODS to XLSX because that can export numbers. Looking at my code, I am explicitly passing widget=import_export.widgets.DecimalWidget(), but I'm not entirely sure if that was needed for exporting numbers, or that's just because of some other changes I have (I have a custom MonetaryResourceWidget that I need to revert for exporting, so replace the widget with DecimalWidget). But you could try if setting the widget explicitly helps.

@claudep
Copy link
Contributor

claudep commented Jan 7, 2023

There is already a test that export and reimport various data as xlsx and ensure that data format is kept:

def test_xlsx_import_set(self):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants