def __init__(self, *styles): super(DefaultStyleSet, self).__init__( NamedStyle(name="Default", alignment=Alignment(vertical="top")), ExtendedStyle( base="Default", name="Empty", ), ExtendedStyle(base="Empty", name="Title", font={"size": 20}), ExtendedStyle(base="Empty", name="Description", font={"color": "FF777777"}), ExtendedStyle(base="Default", name="Header", font={ "bold": True, "color": "FFFFFFFF" }, fill=SolidFill(DEFAULT_ACCENT_COLOR)), ExtendedStyle(base="Header", name="Header, center", alignment={"horizontal": "center"}), ExtendedStyle(base="Default", name="Row"), ExtendedStyle( base="Row", name="Row, string", number_format="@", ), ExtendedStyle(base="Row", name="Row, text", number_format="@", alignment={"wrap_text": True}), ExtendedStyle( base="Row", name="Row, integer", number_format="# ##0", ), ExtendedStyle( base="Row", name="Row, decimal", number_format="0.00", ), ExtendedStyle(base="Row", name="Row, date", alignment={"horizontal": "center"}, number_format="yyyy-mm-dd"), ExtendedStyle(base="Row", name="Row, year", alignment={"horizontal": "center"}, number_format="yyyy"), ExtendedStyle(base="Row", name="Row, time", alignment={"horizontal": "center"}, number_format="h:mm"), *styles)
class OrgStructureWorksheet(TableSheet): name = CharColumn(header="Name") title = CharColumn(header="Title") unit = CharColumn(header="Unit") manager = CharColumn(header="Manager", getter=lambda column, obj: obj.manager.name if obj.manager else "") level = IntColumn(header="Level") hide_excess_columns = False row_styles = [ RowStyle(row_type=1, cell_style=ExtendedStyle(None, lambda x: x + " level 1", fill=SolidFill("bbbbbb"))), RowStyle(row_type=2, cell_style=ExtendedStyle(None, lambda x: x + " level 2", fill=SolidFill("dddddd"))), ] def row_type(self, object, row_number): return object.level
boolean = BoolColumn(header="BoolColumn", row_style="Row, integer", conditional_formatting=bold_true) integer = IntColumn(header="IntColumn", group=True) float = FloatColumn(header="FloatColumn", group=True) datetime = DatetimeColumn(header="DatetimeColumn", group=True) date = DateColumn(header="DateColumn") time = TimeColumn(header="TimeColumn", group=True) formula = FormulaColumn(header="FormulaColumn", formula="=SUM(ColumnDemo[IntColumn])") class DemoWorkbook(TemplatedWorkbook): timestamp = True persons = TemplatedPersonsSheet(sheetname="Persons", active=True) column_demo = ColumnDemoSheet(sheetname="Column demo") if __name__ == "__main__": workbook = DemoWorkbook(template_styles=DefaultStyleSet( ExtendedStyle(base="Default", name="Header", fill=SolidFill( "FF0000")))) workbook.column_demo.write(objects=list(demo_objects(100)), title="Column demo") workbook.persons.write(objects=persons, title="Persons") filename = workbook.save(join(dirname(__file__), "demo.xlsx")) wb = DemoWorkbook(file=filename) print(list(wb.persons.read()))