Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/openpyxl/styles/alignment.py: 91%
43 statements
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
1# Copyright (c) 2010-2023 openpyxl
3from openpyxl.compat import safe_string
5from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
6from openpyxl.descriptors.serialisable import Serialisable
9horizontal_alignments = (
10 "general", "left", "center", "right", "fill", "justify", "centerContinuous",
11 "distributed", )
12vertical_aligments = (
13 "top", "center", "bottom", "justify", "distributed",
14)
16class Alignment(Serialisable):
17 """Alignment options for use in styles."""
19 tagname = "alignment"
21 __fields__ = ('horizontal',
22 'vertical',
23 'textRotation',
24 'wrapText',
25 'shrinkToFit',
26 'indent',
27 'relativeIndent',
28 'justifyLastLine',
29 'readingOrder',
30 )
31 horizontal = NoneSet(values=horizontal_alignments)
32 vertical = NoneSet(values=vertical_aligments)
33 textRotation = NoneSet(values=range(181))
34 textRotation.values.add(255)
35 text_rotation = Alias('textRotation')
36 wrapText = Bool(allow_none=True)
37 wrap_text = Alias('wrapText')
38 shrinkToFit = Bool(allow_none=True)
39 shrink_to_fit = Alias('shrinkToFit')
40 indent = MinMax(min=0, max=255)
41 relativeIndent = MinMax(min=-255, max=255)
42 justifyLastLine = Bool(allow_none=True)
43 readingOrder = Min(min=0)
45 def __init__(self, horizontal=None, vertical=None,
46 textRotation=0, wrapText=None, shrinkToFit=None, indent=0, relativeIndent=0,
47 justifyLastLine=None, readingOrder=0, text_rotation=None,
48 wrap_text=None, shrink_to_fit=None, mergeCell=None):
49 self.horizontal = horizontal
50 self.vertical = vertical
51 self.indent = indent
52 self.relativeIndent = relativeIndent
53 self.justifyLastLine = justifyLastLine
54 self.readingOrder = readingOrder
55 if text_rotation is not None:
56 textRotation = text_rotation
57 if textRotation is not None:
58 self.textRotation = int(textRotation)
59 if wrap_text is not None:
60 wrapText = wrap_text
61 self.wrapText = wrapText
62 if shrink_to_fit is not None:
63 shrinkToFit = shrink_to_fit
64 self.shrinkToFit = shrinkToFit
65 # mergeCell is vestigial
68 def __iter__(self):
69 for attr in self.__attrs__:
70 value = getattr(self, attr)
71 if value is not None and value != 0:
72 yield attr, safe_string(value)