table.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (c) 2010-2019 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Float,
  6. Bool,
  7. Set,
  8. Integer,
  9. NoneSet,
  10. String,
  11. Sequence
  12. )
  13. from .colors import Color
  14. class TableStyleElement(Serialisable):
  15. tagname = "tableStyleElement"
  16. type = Set(values=(['wholeTable', 'headerRow', 'totalRow', 'firstColumn',
  17. 'lastColumn', 'firstRowStripe', 'secondRowStripe', 'firstColumnStripe',
  18. 'secondColumnStripe', 'firstHeaderCell', 'lastHeaderCell',
  19. 'firstTotalCell', 'lastTotalCell', 'firstSubtotalColumn',
  20. 'secondSubtotalColumn', 'thirdSubtotalColumn', 'firstSubtotalRow',
  21. 'secondSubtotalRow', 'thirdSubtotalRow', 'blankRow',
  22. 'firstColumnSubheading', 'secondColumnSubheading',
  23. 'thirdColumnSubheading', 'firstRowSubheading', 'secondRowSubheading',
  24. 'thirdRowSubheading', 'pageFieldLabels', 'pageFieldValues']))
  25. size = Integer(allow_none=True)
  26. dxfId = Integer(allow_none=True)
  27. def __init__(self,
  28. type=None,
  29. size=None,
  30. dxfId=None,
  31. ):
  32. self.type = type
  33. self.size = size
  34. self.dxfId = dxfId
  35. class TableStyle(Serialisable):
  36. tagname = "tableStyle"
  37. name = String()
  38. pivot = Bool(allow_none=True)
  39. table = Bool(allow_none=True)
  40. count = Integer(allow_none=True)
  41. tableStyleElement = Typed(expected_type=TableStyleElement, allow_none=True)
  42. __elements__ = ('tableStyleElement',)
  43. def __init__(self,
  44. name=None,
  45. pivot=None,
  46. table=None,
  47. count=None,
  48. tableStyleElement=None,
  49. ):
  50. self.name = name
  51. self.pivot = pivot
  52. self.table = table
  53. self.count = count
  54. self.tableStyleElement = tableStyleElement
  55. class TableStyleList(Serialisable):
  56. tagname = "tableStyles"
  57. defaultTableStyle = String(allow_none=True)
  58. defaultPivotStyle = String(allow_none=True)
  59. tableStyle = Sequence(expected_type=TableStyle, allow_none=True)
  60. __elements__ = ('tableStyle',)
  61. __attrs__ = ("count", "defaultTableStyle", "defaultPivotStyle")
  62. def __init__(self,
  63. count=None,
  64. defaultTableStyle="TableStyleMedium9",
  65. defaultPivotStyle="PivotStyleLight16",
  66. tableStyle=(),
  67. ):
  68. self.defaultTableStyle = defaultTableStyle
  69. self.defaultPivotStyle = defaultPivotStyle
  70. self.tableStyle = tableStyle
  71. @property
  72. def count(self):
  73. return len(self.tableStyle)