forked from ScoDoc/ScoDoc
empeche noms de feuilles excel invalides
This commit is contained in:
parent
286e9cdc2f
commit
985c6df3b6
@ -72,6 +72,11 @@ def xldate_as_datetime(xldate, datemode=0):
|
||||
|
||||
|
||||
def adjust_sheetname(sheet_name):
|
||||
"""Renvoie un nom convenable pour une feuille excel: < 31 cars, sans caractères spéciaux
|
||||
Le / n'est pas autorisé par exemple.
|
||||
Voir https://xlsxwriter.readthedocs.io/workbook.html#add_worksheet
|
||||
"""
|
||||
sheet_name = scu.make_filename(sheet_name)
|
||||
# Le nom de la feuille ne peut faire plus de 31 caractères.
|
||||
# si la taille du nom de feuille est > 31 on tronque (on pourrait remplacer par 'feuille' ?)
|
||||
return sheet_name[:31]
|
||||
|
@ -480,14 +480,17 @@ def sanitize_string(s):
|
||||
return suppress_accents(s.translate(trans)).replace(" ", "_").replace("\t", "_")
|
||||
|
||||
|
||||
_BAD_FILENAME_CHARS = str.maketrans("", "", ":/\\&")
|
||||
_BAD_FILENAME_CHARS = str.maketrans("", "", ":/\\&[]*?'")
|
||||
|
||||
|
||||
def make_filename(name):
|
||||
"""Try to convert name to a reasonable filename
|
||||
without spaces, (back)slashes, : and without accents
|
||||
"""
|
||||
return suppress_accents(name.translate(_BAD_FILENAME_CHARS)).replace(" ", "_")
|
||||
return (
|
||||
suppress_accents(name.translate(_BAD_FILENAME_CHARS)).replace(" ", "_")
|
||||
or "scodoc"
|
||||
)
|
||||
|
||||
|
||||
VALID_CARS = (
|
||||
|
Loading…
Reference in New Issue
Block a user