forked from ScoDoc/ScoDoc
Merge pull request 'fix true_false' (#168) from jmplace/ScoDoc-Lille:remise_fix_True_False into master
Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/168
This commit is contained in:
commit
c56a4257bd
@ -288,9 +288,31 @@ class ScoExcelSheet:
|
||||
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é
|
||||
"""
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.replace(tzinfo=None) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones)
|
||||
cell = WriteOnlyCell(self.ws, value or "")
|
||||
# adapatation des valeurs si nécessaire
|
||||
if value is None:
|
||||
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:
|
||||
style = self.default_style
|
||||
if "font" in style:
|
||||
@ -312,14 +334,7 @@ class ScoExcelSheet:
|
||||
lines = comment.splitlines()
|
||||
cell.comment.width = 7 * max([len(line) for line in 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
|
||||
|
||||
def make_row(self, values: list, style=None, comments=None):
|
||||
|
@ -777,13 +777,7 @@ def groups_table(
|
||||
m["parcours"] = Se.get_parcours_descr()
|
||||
m["codeparcours"], _ = sco_report.get_codeparcoursetud(etud)
|
||||
|
||||
def dicttakestr(d, keys):
|
||||
r = []
|
||||
for k in keys:
|
||||
r.append(str(d.get(k, "")))
|
||||
return r
|
||||
|
||||
L = [dicttakestr(m, keys) for m in groups_infos.members]
|
||||
L = [[m.get(k, "") for k in keys] for m in groups_infos.members]
|
||||
title = "etudiants_%s" % groups_infos.groups_filename
|
||||
xls = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
|
||||
filename = title
|
||||
|
Loading…
Reference in New Issue
Block a user