fix true_false

This commit is contained in:
Jean-Marie Place 2021-10-16 14:30:35 +02:00
parent c658c7675e
commit 3c38ef4cc0
2 changed files with 27 additions and 18 deletions

View File

@ -288,9 +288,31 @@ class ScoExcelSheet:
value -- contenu de la cellule (texte, numérique, booléen ou date) value -- contenu de la cellule (texte, numérique, booléen ou date)
style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié
""" """
if isinstance(value, datetime.datetime): # adapatation des valeurs si nécessaire
value = value.replace(tzinfo=None) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones) if value is None:
cell = WriteOnlyCell(self.ws, value or "") value = ""
elif value is True:
value = 1
elif value is False:
value = 0
elif isinstance(value, datetime.datetime):
value = value.replace(
tzinfo=None
) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones)
# création de la cellule
cell = WriteOnlyCell(self.ws, value)
# test datatype to overwrite datetime format
if isinstance(value, datetime.date):
cell.data_type = "d"
cell.number_format = FORMAT_DATE_DDMMYY
elif isinstance(value, int) or isinstance(value, float):
cell.data_type = "n"
else:
cell.data_type = "s"
# recopie des styles
if style is None: if style is None:
style = self.default_style style = self.default_style
if "font" in style: if "font" in style:
@ -312,14 +334,7 @@ class ScoExcelSheet:
lines = comment.splitlines() lines = comment.splitlines()
cell.comment.width = 7 * max([len(line) for line in lines]) cell.comment.width = 7 * max([len(line) for line in lines])
cell.comment.height = 20 * len(lines) cell.comment.height = 20 * len(lines)
# test datatype at the end so that datetime format may be overwritten
if isinstance(value, datetime.date):
cell.data_type = "d"
cell.number_format = FORMAT_DATE_DDMMYY
elif isinstance(value, int) or isinstance(value, float):
cell.data_type = "n"
else:
cell.data_type = "s"
return cell return cell
def make_row(self, values: list, style=None, comments=None): def make_row(self, values: list, style=None, comments=None):

View File

@ -777,13 +777,7 @@ def groups_table(
m["parcours"] = Se.get_parcours_descr() m["parcours"] = Se.get_parcours_descr()
m["codeparcours"], _ = sco_report.get_codeparcoursetud(etud) m["codeparcours"], _ = sco_report.get_codeparcoursetud(etud)
def dicttakestr(d, keys): L = [[m.get(k, "") for k in keys] for m in groups_infos.members]
r = []
for k in keys:
r.append(str(d.get(k, "")))
return r
L = [dicttakestr(m, keys) for m in groups_infos.members]
title = "etudiants_%s" % groups_infos.groups_filename title = "etudiants_%s" % groups_infos.groups_filename
xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title) xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
filename = title filename = title