views.py 4.6 KB

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