properties.py 3.1 KB

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