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

Excel export and numbers #149

Closed
murphyalexandre opened this issue Sep 30, 2014 · 5 comments · Fixed by #153
Closed

Excel export and numbers #149

murphyalexandre opened this issue Sep 30, 2014 · 5 comments · Fixed by #153

Comments

@murphyalexandre
Copy link

I'm trying to export numbers to Excel to be able to do sums, but it seems that the integer field is not being exported as a number.

Is there a way to force number export so that the cell format is right on load and we can do functions on those fields ?

@bmihelac
Copy link
Member

Minimal test case would help to identify where the issue is...

@murphyalexandre
Copy link
Author

That's the thing, there's no real test case, only a file that, when opened up in Excel, doesn't have the 'number' format at thus cannot be used in functions.

@kupuguy
Copy link

kupuguy commented Oct 3, 2014

The issue here is that the default Widget.render() returns force_text(value) which forces any numbers to a text representation.

This seems to be a general problem with both importing and exporting Excel data. For example, I just tried to import an Excel sheet and one of the columns in my model is a models.DateField. The spreadsheet contains dates in the relevant column, which means the Dataset gets floating point numbers (Excel stores dates as floating point). The import_export DateWidget then tries to call strptime on the floating point value.

I think the widget interface needs to know which external format is required. Text is fine for the text formats but just doesn't hack it for numbers, booleans, and date/time values.

bmihelac added a commit that referenced this issue Oct 3, 2014
@bmihelac
Copy link
Member

bmihelac commented Oct 3, 2014

@murphyalexandre can you try changes in 149-excel-export-and-numbers branch and let me know if this fix the issue persists.

@kupuguy good note, I agree for not converting numeric values to string. If format needs a string it will convert it itself.
Regarding dates, DateWidget currently has optional format argument and that is why it needs to be a string. Date fields could easily use IntegerWidget, of course then it will be represented in all formats as numbers. Let's open new issue for this.

@murphyalexandre
Copy link
Author

That last commit did the trick. Thank you so much!

craiglabenz pushed a commit to craiglabenz/django-import-export that referenced this issue Oct 18, 2014
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

Successfully merging a pull request may close this issue.

3 participants