views.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors import (
  3. Bool,
  4. Integer,
  5. String,
  6. Set,
  7. Float,
  8. Typed,
  9. NoneSet,
  10. Sequence,
  11. )
  12. from openpyxl.descriptors.excel import ExtensionList
  13. from openpyxl.descriptors.serialisable import Serialisable
  14. class Pane(Serialisable):
  15. xSplit = Float(allow_none=True)
  16. ySplit = Float(allow_none=True)
  17. topLeftCell = String(allow_none=True)
  18. activePane = Set(values=("bottomRight", "topRight", "bottomLeft", "topLeft"))
  19. state = Set(values=("split", "frozen", "frozenSplit"))
  20. def __init__(self,
  21. xSplit=None,
  22. ySplit=None,
  23. topLeftCell=None,
  24. activePane="topLeft",
  25. state="split"):
  26. self.xSplit = xSplit
  27. self.ySplit = ySplit
  28. self.topLeftCell = topLeftCell
  29. self.activePane = activePane
  30. self.state = state
  31. class Selection(Serialisable):
  32. pane = NoneSet(values=("bottomRight", "topRight", "bottomLeft", "topLeft"))
  33. activeCell = String(allow_none=True)
  34. activeCellId = Integer(allow_none=True)
  35. sqref = String(allow_none=True)
  36. def __init__(self,
  37. pane=None,
  38. activeCell="A1",
  39. activeCellId=None,
  40. sqref="A1"):
  41. self.pane = pane
  42. self.activeCell = activeCell
  43. self.activeCellId = activeCellId
  44. self.sqref = sqref
  45. class SheetView(Serialisable):
  46. """Information about the visible portions of this sheet."""
  47. tagname = "sheetView"
  48. windowProtection = Bool(allow_none=True)
  49. showFormulas = Bool(allow_none=True)
  50. showGridLines = Bool(allow_none=True)
  51. showRowColHeaders = Bool(allow_none=True)
  52. showZeros = Bool(allow_none=True)
  53. rightToLeft = Bool(allow_none=True)
  54. tabSelected = Bool(allow_none=True)
  55. showRuler = Bool(allow_none=True)
  56. showOutlineSymbols = Bool(allow_none=True)
  57. defaultGridColor = Bool(allow_none=True)
  58. showWhiteSpace = Bool(allow_none=True)
  59. view = NoneSet(values=("normal", "pageBreakPreview", "pageLayout"))
  60. topLeftCell = String(allow_none=True)
  61. colorId = Integer(allow_none=True)
  62. zoomScale = Integer(allow_none=True)
  63. zoomScaleNormal = Integer(allow_none=True)
  64. zoomScaleSheetLayoutView = Integer(allow_none=True)
  65. zoomScalePageLayoutView = Integer(allow_none=True)
  66. zoomToFit = Bool(allow_none=True) # Chart sheets only
  67. workbookViewId = Integer()
  68. selection = Sequence(expected_type=Selection)
  69. pane = Typed(expected_type=Pane, allow_none=True)
  70. def __init__(self,
  71. windowProtection=None,
  72. showFormulas=None,
  73. showGridLines=None,
  74. showRowColHeaders=None,
  75. showZeros=None,
  76. rightToLeft=None,
  77. tabSelected=None,
  78. showRuler=None,
  79. showOutlineSymbols=None,
  80. defaultGridColor=None,
  81. showWhiteSpace=None,
  82. view=None,
  83. topLeftCell=None,
  84. colorId=None,
  85. zoomScale=None,
  86. zoomScaleNormal=None,
  87. zoomScaleSheetLayoutView=None,
  88. zoomScalePageLayoutView=None,
  89. zoomToFit=None,
  90. workbookViewId=0,
  91. selection=None,
  92. pane=None,):
  93. self.windowProtection = windowProtection
  94. self.showFormulas = showFormulas
  95. self.showGridLines = showGridLines
  96. self.showRowColHeaders = showRowColHeaders
  97. self.showZeros = showZeros
  98. self.rightToLeft = rightToLeft
  99. self.tabSelected = tabSelected
  100. self.showRuler = showRuler
  101. self.showOutlineSymbols = showOutlineSymbols
  102. self.defaultGridColor = defaultGridColor
  103. self.showWhiteSpace = showWhiteSpace
  104. self.view = view
  105. self.topLeftCell = topLeftCell
  106. self.colorId = colorId
  107. self.zoomScale = zoomScale
  108. self.zoomScaleNormal = zoomScaleNormal
  109. self.zoomScaleSheetLayoutView = zoomScaleSheetLayoutView
  110. self.zoomScalePageLayoutView = zoomScalePageLayoutView
  111. self.zoomToFit = zoomToFit
  112. self.workbookViewId = workbookViewId
  113. self.pane = pane
  114. if selection is None:
  115. selection = (Selection(), )
  116. self.selection = selection
  117. class SheetViewList(Serialisable):
  118. tagname = "sheetViews"
  119. sheetView = Sequence(expected_type=SheetView, )
  120. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  121. __elements__ = ('sheetView',)
  122. def __init__(self,
  123. sheetView=None,
  124. extLst=None,
  125. ):
  126. if sheetView is None:
  127. sheetView = [SheetView()]
  128. self.sheetView = sheetView
  129. @property
  130. def active(self):
  131. """
  132. Returns the first sheet view which is assumed to be active
  133. """
  134. return self.sheetView[0]