ole.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. from openpyxl.descriptors.serialisable import Serialisable
  4. from openpyxl.descriptors import (
  5. Typed,
  6. Integer,
  7. String,
  8. Set,
  9. Bool,
  10. Sequence,
  11. )
  12. from openpyxl.drawing.spreadsheet_drawing import AnchorMarker
  13. from openpyxl.xml.constants import SHEET_DRAWING_NS
  14. class ObjectAnchor(Serialisable):
  15. tagname = "anchor"
  16. _from = Typed(expected_type=AnchorMarker, namespace=SHEET_DRAWING_NS)
  17. to = Typed(expected_type=AnchorMarker, namespace=SHEET_DRAWING_NS)
  18. moveWithCells = Bool(allow_none=True)
  19. sizeWithCells = Bool(allow_none=True)
  20. z_order = Integer(allow_none=True, hyphenated=True)
  21. def __init__(self,
  22. _from=None,
  23. to=None,
  24. moveWithCells=False,
  25. sizeWithCells=False,
  26. z_order=None,
  27. ):
  28. self._from = _from
  29. self.to = to
  30. self.moveWithCells = moveWithCells
  31. self.sizeWithCells = sizeWithCells
  32. self.z_order = z_order
  33. class ObjectPr(Serialisable):
  34. tagname = "objectPr"
  35. anchor = Typed(expected_type=ObjectAnchor, )
  36. locked = Bool(allow_none=True)
  37. defaultSize = Bool(allow_none=True)
  38. _print = Bool(allow_none=True)
  39. disabled = Bool(allow_none=True)
  40. uiObject = Bool(allow_none=True)
  41. autoFill = Bool(allow_none=True)
  42. autoLine = Bool(allow_none=True)
  43. autoPict = Bool(allow_none=True)
  44. macro = String()
  45. altText = String(allow_none=True)
  46. dde = Bool(allow_none=True)
  47. __elements__ = ('anchor',)
  48. def __init__(self,
  49. anchor=None,
  50. locked=True,
  51. defaultSize=True,
  52. _print=True,
  53. disabled=False,
  54. uiObject=False,
  55. autoFill=True,
  56. autoLine=True,
  57. autoPict=True,
  58. macro=None,
  59. altText=None,
  60. dde=False,
  61. ):
  62. self.anchor = anchor
  63. self.locked = locked
  64. self.defaultSize = defaultSize
  65. self._print = _print
  66. self.disabled = disabled
  67. self.uiObject = uiObject
  68. self.autoFill = autoFill
  69. self.autoLine = autoLine
  70. self.autoPict = autoPict
  71. self.macro = macro
  72. self.altText = altText
  73. self.dde = dde
  74. class OleObject(Serialisable):
  75. tagname = "oleObject"
  76. objectPr = Typed(expected_type=ObjectPr, allow_none=True)
  77. progId = String(allow_none=True)
  78. dvAspect = Set(values=(['DVASPECT_CONTENT', 'DVASPECT_ICON']))
  79. link = String(allow_none=True)
  80. oleUpdate = Set(values=(['OLEUPDATE_ALWAYS', 'OLEUPDATE_ONCALL']))
  81. autoLoad = Bool(allow_none=True)
  82. shapeId = Integer()
  83. __elements__ = ('objectPr',)
  84. def __init__(self,
  85. objectPr=None,
  86. progId=None,
  87. dvAspect='DVASPECT_CONTENT',
  88. link=None,
  89. oleUpdate=None,
  90. autoLoad=False,
  91. shapeId=None,
  92. ):
  93. self.objectPr = objectPr
  94. self.progId = progId
  95. self.dvAspect = dvAspect
  96. self.link = link
  97. self.oleUpdate = oleUpdate
  98. self.autoLoad = autoLoad
  99. self.shapeId = shapeId
  100. class OleObjects(Serialisable):
  101. tagname = "oleObjects"
  102. oleObject = Sequence(expected_type=OleObject)
  103. __elements__ = ('oleObject',)
  104. def __init__(self,
  105. oleObject=(),
  106. ):
  107. self.oleObject = oleObject