Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Copyright (c) 2010-2020 openpyxl 

2 

3from openpyxl.descriptors import ( 

4 Integer, 

5 String, 

6 Typed, 

7 Sequence, 

8 Alias, 

9) 

10from openpyxl.descriptors.serialisable import Serialisable 

11from openpyxl.styles import ( 

12 Font, 

13 Fill, 

14 GradientFill, 

15 PatternFill, 

16 Border, 

17 Alignment, 

18 Protection, 

19 ) 

20from .numbers import NumberFormat 

21 

22 

23class DifferentialStyle(Serialisable): 

24 

25 tagname = "dxf" 

26 

27 __elements__ = ("font", "numFmt", "fill", "alignment", "border", "protection") 

28 

29 font = Typed(expected_type=Font, allow_none=True) 

30 numFmt = Typed(expected_type=NumberFormat, allow_none=True) 

31 fill = Typed(expected_type=Fill, allow_none=True) 

32 alignment = Typed(expected_type=Alignment, allow_none=True) 

33 border = Typed(expected_type=Border, allow_none=True) 

34 protection = Typed(expected_type=Protection, allow_none=True) 

35 

36 def __init__(self, 

37 font=None, 

38 numFmt=None, 

39 fill=None, 

40 alignment=None, 

41 border=None, 

42 protection=None, 

43 extLst=None, 

44 ): 

45 self.font = font 

46 self.numFmt = numFmt 

47 self.fill = fill 

48 self.alignment = alignment 

49 self.border = border 

50 self.protection = protection 

51 self.extLst = extLst 

52 

53 

54class DifferentialStyleList(Serialisable): 

55 """ 

56 Deduping container for differential styles. 

57 """ 

58 

59 tagname = "dxfs" 

60 

61 dxf = Sequence(expected_type=DifferentialStyle) 

62 styles = Alias("dxf") 

63 

64 

65 def __init__(self, dxf=()): 

66 self.dxf = dxf 

67 

68 

69 def append(self, dxf): 

70 """ 

71 Check to see whether style already exists and append it if does not. 

72 """ 

73 if not isinstance(dxf, DifferentialStyle): 

74 raise TypeError('expected ' + str(DifferentialStyle)) 

75 if dxf in self.styles: 

76 return 

77 self.styles.append(dxf) 

78 

79 

80 def add(self, dxf): 

81 """ 

82 Add a differential style and return its index 

83 """ 

84 self.append(dxf) 

85 return self.styles.index(dxf) 

86 

87 

88 def __bool__(self): 

89 return bool(self.styles) 

90 

91 

92 

93 def __getitem__(self, idx): 

94 return self.styles[idx]