From 8ab9a67fa678195f5d1609690e1302297e2ede87 Mon Sep 17 00:00:00 2001 From: Jean-Marie Place Date: Tue, 5 Oct 2021 12:09:20 +0200 Subject: [PATCH] =?UTF-8?q?autorise=20les=20cha=C3=AEnes=20JJ/MM/AAAA=20co?= =?UTF-8?q?mme=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_excel.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index 6904062cf..ffb020029 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -65,10 +65,16 @@ class COLORS(Enum): def xldate_as_datetime(xldate, datemode=0): - """Conversion d'une date Excel en date + """Conversion d'une date Excel en datetime python + Deux formats de chaîne acceptés: + * JJ/MM/YYYY (chaîne naïve) + * Date ISO (valeur de type date lue dans la feuille) Peut lever une ValueError """ - return openpyxl.utils.datetime.from_ISO8601(xldate) + try: + return datetime.datetime.strptime(xldate, "%d/%m/%Y") + except: + return openpyxl.utils.datetime.from_ISO8601(xldate) def adjust_sheetname(sheet_name):