Skip to content

Commit

Permalink
tabular: format date typed cells for humans
Browse files Browse the repository at this point in the history
 * The tabular renderer for spreadsheets using xlrd was displaying
   date fields as floats, since that is how they are stored in the
   spreadsheet.  xlrd can detect if a field was formatted as a date
   and provides methods to turn these values into python datetime
   objects.  One drawback is that user-local timezone information is
   not available, so MFR will always render datetimes as UTC.

   See:
     http://xlrd.readthedocs.io/en/latest/dates.html
     http://xlrd.readthedocs.io/en/latest/api.html#module-xlrd.xldate
  • Loading branch information
Johnetordoff authored and felliott committed Feb 15, 2017
1 parent 0c2eb23 commit d0a7ad6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mfr/extensions/tabular/libs/xlrd_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ def xlsx_xlrd(fp):
for index, value in enumerate(fields)
]

data = [
dict(zip(fields, sheet.row_values(row_index)))
for row_index in range(1, sheet.nrows)
]
data = []
for i in range(1, sheet.nrows):
row = []
for cell in sheet.row(i):
if cell.ctype == xlrd.XL_CELL_DATE:
value = xlrd.xldate.xldate_as_datetime(cell.value, wb.datemode).isoformat()
else:
value = cell.value
row.append(value)
data.append(dict(zip(fields, row)))

header = header_population(fields)
sheets[sheet.name] = (header, data)
Expand Down

0 comments on commit d0a7ad6

Please sign in to comment.