merging cells

This commit is contained in:
Jean-Marie Place 2024-06-30 11:22:07 +02:00
parent 55b42509de
commit db39c89257
4 changed files with 56 additions and 28 deletions

View File

@ -443,7 +443,7 @@ class ScoExcelSheet:
for row in self.rows:
self.ws.append(row)
def generate(self, column_widths=None):
def generate(self, column_widths=None, merged=[]):
"""génération d'un classeur mono-feuille"""
# this method makes sense for standalone worksheet (else call workbook.generate())
if self.wb is None: # embeded sheet
@ -452,12 +452,16 @@ class ScoExcelSheet:
# construction d'un flux
# https://openpyxl.readthedocs.io/en/stable/tutorial.html#saving-as-a-stream
self.prepare()
for tuple in merged:
top, left, bottom, right = tuple
self.ws.merge_cells(
start_row=top, end_row=bottom, start_column=left, end_column=right
)
# largeur des colonnes
if column_widths:
for k, v in column_widths.items():
self.set_column_dimension_width(k, v)
if self.auto_filter is not None:
self.ws.auto_filter.ref = self.auto_filter
with NamedTemporaryFile() as tmp:

View File

@ -77,7 +77,6 @@ def make_alignment(halign=None, valign=None, orientation=None, style=None):
if orientation:
alignment.rota = orientation
if alignment and style:
breakpoint()
style["alignment"] = alignment
return alignment

View File

@ -474,8 +474,6 @@ imports = {}
def compute_sems(etud, formation_id, formation_titre, descripteurs, Se):
inscriptions = {}
rsems = Se.sems[:] # copy
# breakpoint()
# rsems.reverse()
if formation_id not in imports:
imports[formation_id] = {}
for (

View File

@ -61,7 +61,8 @@ import sco_version
from app.scodoc.sco_excel import excel_make_style, COLORS
from app.scodoc.sco_excel_add import make_pattern
from app.scodoc.sco_prepajury_formats import Formatter
from app.tables.jury_recap import TableJury
from app.tables.recap import TableRecap
COLORS = {
"ETUDIANT": ["FFFF99"],
@ -405,7 +406,7 @@ class Export:
parcours_id = self.nt.etuds_parcour_id[etud.id]
if parcours_id is not None and parcours_id not in self.data_comp:
parcours = db.session.get(ApcParcours, parcours_id)
self.data_comp[parcours_id] = parcours
self.data_comp[parcours_id] = parcours
def load_formsemestre_data(self, formsemestre: FormSemestre):
sem_id = formsemestre.id
@ -413,6 +414,14 @@ class Export:
self.data_sems[sem_id]["formsemestre"] = formsemestre
nt = res_sem.load_formsemestre_results(formsemestre)
self.data_sems[sem_id]["nt"] = nt
# self.data_sems[sem_id]["recap"] = TableJury(
# nt,
# convert_values=False,
# include_evaluations=False,
# mode_jury=True,
# read_only=True,
# )
current_app.logger.info(f"Table semestre {sem_id} chargée.")
def load_formsemestre(self, etud, session):
for sem in session.sems:
@ -448,7 +457,6 @@ class Export:
etud, self.formsemestre.formation
)
# self.data_etud[etud.id]["bulletin_sem"] = bulletins_sem.bulletin_etud(etud)
breakpoint()
def load_data(self):
self.load_parcours()
@ -458,7 +466,6 @@ class Export:
self.data_etud[etud.id]["sems"] = {}
self.load_etu(etud)
session = sco_cursus.get_situation_etud_cursus(etud, self.formsemestre_id)
breakpoint()
self.data_etud[etud.id]["cursus"] = session.parcours
self.load_formsemestre(etud, session)
@ -504,21 +511,15 @@ class Export:
styles[row_no].append(excel_make_style(bgcolor=color[level2]))
compte += nbelt
# current_app.logger.info(f" {row_no}, {left}, {nbelt} ")
# sheet.ws.merge_cells(
# start_row=row_no + 1,
# end_row=row_no + 1,
# start_column=left + 1,
# end_column=left + nbelt + 1,
# )
return compte
else:
return 1
def header_append(self, raws, items, row_no):
def header_append(self, rows, items, row_no):
if row_no <= 4:
if items is None:
raws[row_no].append("")
self.header_append(raws, None, row_no + 1)
rows[row_no].append("")
self.header_append(rows, None, row_no + 1)
return 1
else:
compte = 0
@ -526,35 +527,55 @@ class Export:
if item != "COLOR":
detail = items[item]
if item[0] != "+":
raws[row_no].append(item)
rows[row_no].append(item)
else:
raws[row_no].append(item[1:])
nbelt = self.header_append(raws, detail, row_no + 1)
rows[row_no].append(item[1:])
nbelt = self.header_append(rows, detail, row_no + 1)
for _ in range(1, nbelt):
raws[row_no].append("")
rows[row_no].append("")
compte += nbelt
return compte
else:
return 1
def write_header(self, sheet):
raws = [[], [], [], [], []]
rows = [[], [], [], [], []]
styles = [[], [], [], [], []]
col_no = 0
raw_no = 0
self.header_format(styles, CATEGORIES, 0, 0, ["FFFF00"], 0)
self.header_append(raws, CATEGORIES, 0)
self.header_append(rows, CATEGORIES, 0)
for i in range(0, 4):
sheet.append_row(
sheet.make_row(
raws[i],
rows[i],
styles[i],
# style=excel_make_style(
# font_name="Calibri", size=12, bold=False, bgcolor="D0FFFF"
# ),
)
)
sheet.ws.merge_cells(start_row=9, end_row=8, start_column=1, end_column=10)
# sheet.ws.merge_cells(start_row=5, end_row=5, start_column=1, end_column=9)
# sheet.ws.merge_cells("A5:J5")
def merge_header(self, frames, element, top, left):
if element is None or top >= 8:
frames.append((top, left, 8, left))
return left + 1
else:
tuples = []
current = left
for item in element:
detail = element[item]
next = self.merge_header(
frames,
detail,
top + 1,
current,
)
current = next
frames.append((top, left, top, next - 1))
return next
def feuille_preparation_lille(formsemestre_id):
@ -582,6 +603,9 @@ def feuille_preparation_lille(formsemestre_id):
# "Feuille préparation Jury %s" % scu.unescape_html(sem["titreannee"]), style_bold
# )
sheet.append_blank_row()
sheet.append_blank_row()
sheet.append_blank_row()
sheet.append_blank_row()
export.write_header(sheet)
# Ligne de titre
@ -699,7 +723,7 @@ def feuille_preparation_lille(formsemestre_id):
# UE : Correspondances acronyme et titre complet
sheet.append_blank_row()
# export.merge_header(sheet, CATEGORIES["ETUDIANT"]["Absences"]["Tot."], 6, 8, 5)
# sheet.append_single_cell_row("Titre des UE")
# if prev_moy:
# for ue in ntp.get_ues_stat_dict(filter_sport=True):
@ -717,7 +741,10 @@ def feuille_preparation_lille(formsemestre_id):
# current_user,
# )
# )
xls = sheet.generate()
breakpoint()
merged = []
export.merge_header(merged, CATEGORIES, 4, 1)
xls = sheet.generate(merged=merged)
flash("Feuille préparation jury générée")
return scu.send_file(
xls,