Merge pull request 'correction affichage sur 2 décimales dans les fichiers xlsx générés' (#114) from jmplace/ScoDoc-Lille:fix_excel_numbers into master
Reviewed-on: https://scodoc.org/git/viennet/ScoDoc/pulls/114
This commit is contained in:
commit
671467663d
@ -695,10 +695,10 @@ class SeqGenTable(object):
|
||||
|
||||
def excel(self):
|
||||
"""Export des genTables dans un unique fichier excel avec plusieurs feuilles tagguées"""
|
||||
book = sco_excel.Workbook() # pylint: disable=no-member
|
||||
book = sco_excel.ScoExcelBook() # pylint: disable=no-member
|
||||
for (_, gt) in self.genTables.items():
|
||||
gt.excel(wb=book) # Ecrit dans un fichier excel
|
||||
return book.savetostr()
|
||||
return book.generate()
|
||||
|
||||
|
||||
# ----- Exemple d'utilisation minimal.
|
||||
|
@ -38,6 +38,7 @@ import openpyxl.utils.datetime
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.cell import WriteOnlyCell
|
||||
from openpyxl.styles import Font, Border, Side, Alignment, PatternFill
|
||||
from openpyxl.styles.numbers import FORMAT_NUMBER_00, FORMAT_GENERAL
|
||||
from openpyxl.comments import Comment
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -169,7 +170,7 @@ def excel_make_style(
|
||||
bgcolor: COLORS = None,
|
||||
halign=None,
|
||||
valign=None,
|
||||
format_number=None,
|
||||
number_format=None,
|
||||
font_name="Arial",
|
||||
size=10,
|
||||
):
|
||||
@ -180,7 +181,7 @@ def excel_make_style(
|
||||
bgcolor -- la couleur de fond
|
||||
halign -- alignement horizontal ("left", "right", "center")
|
||||
valign -- alignement vertical ("top", "bottom", "center")
|
||||
format_number -- formattage du contenu ("General", "@", ...)
|
||||
number_format -- formattage du contenu ("General", "@", ...)
|
||||
font_name -- police
|
||||
size -- taille de police
|
||||
"""
|
||||
@ -204,10 +205,10 @@ def excel_make_style(
|
||||
"center": "center",
|
||||
}[valign]
|
||||
style["alignment"] = al
|
||||
if format_number is None:
|
||||
style["format_number"] = "General"
|
||||
if number_format is None:
|
||||
style["number_format"] = FORMAT_GENERAL
|
||||
else:
|
||||
style["format_number"] = format_number
|
||||
style["number_format"] = number_format
|
||||
return style
|
||||
|
||||
|
||||
@ -400,16 +401,18 @@ def excel_simple_table(
|
||||
]
|
||||
)
|
||||
default_style = excel_make_style()
|
||||
text_style = excel_make_style(format_number="@")
|
||||
text_style = excel_make_style(number_format=FORMAT_GENERAL)
|
||||
int_style = excel_make_style()
|
||||
float_style = excel_make_style(number_format=FORMAT_NUMBER_00)
|
||||
for line in lines:
|
||||
cells = []
|
||||
for it in line:
|
||||
# safety net: allow only str, int and float
|
||||
# TODO Plus de type Long en Python 3 ?
|
||||
# if isinstance(it, long): # XXX
|
||||
# it = int(it) # assume all ScoDoc longs fits in int !
|
||||
cell_style = default_style
|
||||
if type(it) not in (int, float): # XXX A REVOIR
|
||||
if type(it) == float:
|
||||
cell_style = float_style
|
||||
elif type(it) == int:
|
||||
cell_style = int_style
|
||||
else:
|
||||
cell_style = text_style
|
||||
cells.append(ws.make_cell(it, cell_style))
|
||||
ws.append_row(cells)
|
||||
@ -472,7 +475,7 @@ def excel_feuille_saisie(e, titreannee, description, lines):
|
||||
}
|
||||
style_notes = {
|
||||
"font": font_bold,
|
||||
"number_format": "General",
|
||||
"number_format": FORMAT_GENERAL,
|
||||
"fill": fill_light_yellow,
|
||||
"border": border_top,
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
"""
|
||||
import time
|
||||
|
||||
from openpyxl.styles.numbers import FORMAT_NUMBER_00
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.scodoc import sco_abs
|
||||
from app.scodoc import sco_groups
|
||||
@ -162,9 +164,11 @@ def feuille_preparation_jury(formsemestre_id, REQUEST):
|
||||
style_moy = sco_excel.excel_make_style(
|
||||
bold=True, halign="center", bgcolor=sco_excel.COLORS.LIGHT_YELLOW
|
||||
)
|
||||
style_note = sco_excel.excel_make_style(halign="right", format_number="General")
|
||||
style_note = sco_excel.excel_make_style(
|
||||
halign="right", number_format=FORMAT_NUMBER_00
|
||||
)
|
||||
style_note_bold = sco_excel.excel_make_style(
|
||||
halign="right", bold=True, format_number="General"
|
||||
halign="right", bold=True, number_format="General"
|
||||
)
|
||||
|
||||
# Première ligne
|
||||
|
Loading…
Reference in New Issue
Block a user