forked from ScoDoc/ScoDoc
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import openpyxl.cell
|
|
from openpyxl.cell import Cell
|
|
|
|
from app.but.prepajury_xl import (
|
|
ScoExcelSheet,
|
|
)
|
|
from app.but.prepajury_xl_format import (
|
|
SCO_HALIGN,
|
|
SCO_VALIGN,
|
|
SCO_FONTNAME,
|
|
SCO_FONTSIZE,
|
|
FMT,
|
|
Sco_Style,
|
|
)
|
|
|
|
base_signature = (
|
|
FMT.FONT_NAME.set(SCO_FONTNAME.FONTNAME_CALIBRI)
|
|
+ FMT.FONT_SIZE.set(SCO_FONTSIZE.FONTSIZE_13)
|
|
+ FMT.ALIGNMENT_HALIGN.set(SCO_HALIGN.HALIGN_CENTER)
|
|
+ FMT.ALIGNMENT_VALIGN.set(SCO_VALIGN.VALIGN_CENTER)
|
|
)
|
|
|
|
|
|
def set_cell(
|
|
ws: Cell,
|
|
row: int,
|
|
column: int,
|
|
text: str = "",
|
|
from_signature: int = 0,
|
|
composition: list = [],
|
|
):
|
|
cell = ws.cell(row, column)
|
|
cell.value = text
|
|
sign = FMT.compose(composition, from_signature)
|
|
style: Sco_Style = FMT.style(sign)
|
|
style.apply(cell)
|
|
|
|
|
|
class Sco_Cell:
|
|
def __init__(
|
|
self, text: str = None, signature: int = base_signature, comment: str = None
|
|
):
|
|
self.text = text
|
|
self.signature = signature or base_signature
|
|
self.comment = comment
|
|
|
|
def format(self, value=None):
|
|
self.signature = FMT.ALL.composante.write(self.signature, value)
|
|
|
|
def copy(self, cell: openpyxl.cell.Cell):
|
|
cell.value = self.text
|
|
style: Sco_Style = FMT.style(self.signature)
|
|
style.apply(cell)
|
|
|
|
def make_cell(self, worksheet: ScoExcelSheet):
|
|
cell = worksheet.make_cell(self.text or "")
|
|
style: Sco_Style = FMT.style(self.signature)
|
|
style.apply(cell)
|
|
return cell
|