properties.py 3.0 KB

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