Closed askoretskiy closed 5 years ago
I just got stumbled on this code:
for row in results:
column_count = 0
row_count += 1
for column_name, value in row.items():
if column_name == 'row_color':
continue
column_count += 1
cell = ws.cell(row=row_count,
column=column_count,
value='{}'.format(value)) # <----- WTF? That would convert everything to text
cell.style = body_style
IIRC, this was put in to handle dates. We are limited by the data passed from Django REST Framework. I'll dig in and see if (a) the metadata of column type is provided to the renderer by DRF, and (b) if it is worth building out a mapping.
@askoretskiy After digging into the code (it had been a while!), I'm trying to recall why that was put into place. I've done some testing against my company's data endpoints to look for the exception it was handling, but they seem to be working well. I've pushed out a change as commit 497772a; any chance you can test against the latest master and see if it is working for you now?
Fixed here; will be released in about 10 minutes to PyPI: https://github.com/wharton/drf-renderer-xlsx/commit/497772a9d797dc1b2e0bbbeb695278a87e7fff4a#diff-643b3dcb780e20c4ead30d169b1ff991R158
My serializer returns type-reach content:
But in resulting XLSX all these cells are strings. E.g.
'123
I didn't find in documentation any way to specify that given cell is integer / float / data / boolean.