Source code

Download source archive ↓

src/openpyxl/worksheet/properties.py

1# Copyright (c) 2010-2024 openpyxl
2
3"""Worksheet Properties"""
4
5from openpyxl.descriptors.serialisable import Serialisable
6from openpyxl.descriptors import String, Bool, Typed
7from openpyxl.styles.colors import ColorDescriptor
8
9
10class Outline(Serialisable):
11
12    tagname = "outlinePr"
13
14    applyStyles = Bool(allow_none=True)
15    summaryBelow = Bool(allow_none=True)
16    summaryRight = Bool(allow_none=True)
17    showOutlineSymbols = Bool(allow_none=True)
18
19
20    def __init__(self,
21                 applyStyles=None,
22                 summaryBelow=None,
23                 summaryRight=None,
24                 showOutlineSymbols=None
25                 ):
26        self.applyStyles = applyStyles
27        self.summaryBelow = summaryBelow
28        self.summaryRight = summaryRight
29        self.showOutlineSymbols = showOutlineSymbols
30
31
32class PageSetupProperties(Serialisable):
33
34    tagname = "pageSetUpPr"
35
36    autoPageBreaks = Bool(allow_none=True)
37    fitToPage = Bool(allow_none=True)
38
39    def __init__(self, autoPageBreaks=None, fitToPage=None):
40        self.autoPageBreaks = autoPageBreaks
41        self.fitToPage = fitToPage
42
43
44class WorksheetProperties(Serialisable):
45
46    tagname = "sheetPr"
47
48    codeName = String(allow_none=True)
49    enableFormatConditionsCalculation = Bool(allow_none=True)
50    filterMode = Bool(allow_none=True)
51    published = Bool(allow_none=True)
52    syncHorizontal = Bool(allow_none=True)
53    syncRef = String(allow_none=True)
54    syncVertical = Bool(allow_none=True)
55    transitionEvaluation = Bool(allow_none=True)
56    transitionEntry = Bool(allow_none=True)
57    tabColor = ColorDescriptor(allow_none=True)
58    outlinePr = Typed(expected_type=Outline, allow_none=True)
59    pageSetUpPr = Typed(expected_type=PageSetupProperties, allow_none=True)
60
61    __elements__ = ('tabColor', 'outlinePr', 'pageSetUpPr')
62
63
64    def __init__(self,
65                 codeName=None,
66                 enableFormatConditionsCalculation=None,
67                 filterMode=None,
68                 published=None,
69                 syncHorizontal=None,
70                 syncRef=None,
71                 syncVertical=None,
72                 transitionEvaluation=None,
73                 transitionEntry=None,
74                 tabColor=None,
75                 outlinePr=None,
76                 pageSetUpPr=None
77                 ):
78        """ Attributes """
79        self.codeName = codeName
80        self.enableFormatConditionsCalculation = enableFormatConditionsCalculation
81        self.filterMode = filterMode
82        self.published = published
83        self.syncHorizontal = syncHorizontal
84        self.syncRef = syncRef
85        self.syncVertical = syncVertical
86        self.transitionEvaluation = transitionEvaluation
87        self.transitionEntry = transitionEntry
88        """ Elements """
89        self.tabColor = tabColor
90        if outlinePr is None:
91            self.outlinePr = Outline(summaryBelow=True, summaryRight=True)
92        else:
93            self.outlinePr = outlinePr
94
95        if pageSetUpPr is None:
96            pageSetUpPr = PageSetupProperties()
97        self.pageSetUpPr = pageSetUpPr