cache.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Bool,
  6. Float,
  7. Set,
  8. NoneSet,
  9. String,
  10. Integer,
  11. DateTime,
  12. Sequence,
  13. )
  14. from openpyxl.descriptors.excel import (
  15. HexBinary,
  16. ExtensionList,
  17. Relation,
  18. )
  19. from openpyxl.descriptors.nested import NestedInteger
  20. from openpyxl.descriptors.sequence import (
  21. NestedSequence,
  22. MultiSequence,
  23. MultiSequencePart,
  24. )
  25. from openpyxl.xml.constants import SHEET_MAIN_NS
  26. from openpyxl.xml.functions import tostring
  27. from openpyxl.packaging.relationship import (
  28. RelationshipList,
  29. Relationship,
  30. get_rels_path
  31. )
  32. from .table import (
  33. PivotArea,
  34. Reference,
  35. )
  36. from .fields import (
  37. Boolean,
  38. Error,
  39. Missing,
  40. Number,
  41. Text,
  42. TupleList,
  43. DateTimeField,
  44. )
  45. class MeasureDimensionMap(Serialisable):
  46. tagname = "map"
  47. measureGroup = Integer(allow_none=True)
  48. dimension = Integer(allow_none=True)
  49. def __init__(self,
  50. measureGroup=None,
  51. dimension=None,
  52. ):
  53. self.measureGroup = measureGroup
  54. self.dimension = dimension
  55. class MeasureGroup(Serialisable):
  56. tagname = "measureGroup"
  57. name = String()
  58. caption = String()
  59. def __init__(self,
  60. name=None,
  61. caption=None,
  62. ):
  63. self.name = name
  64. self.caption = caption
  65. class PivotDimension(Serialisable):
  66. tagname = "dimension"
  67. measure = Bool()
  68. name = String()
  69. uniqueName = String()
  70. caption = String()
  71. def __init__(self,
  72. measure=None,
  73. name=None,
  74. uniqueName=None,
  75. caption=None,
  76. ):
  77. self.measure = measure
  78. self.name = name
  79. self.uniqueName = uniqueName
  80. self.caption = caption
  81. class CalculatedMember(Serialisable):
  82. tagname = "calculatedMember"
  83. name = String()
  84. mdx = String()
  85. memberName = String(allow_none=True)
  86. hierarchy = String(allow_none=True)
  87. parent = String(allow_none=True)
  88. solveOrder = Integer(allow_none=True)
  89. set = Bool()
  90. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  91. __elements__ = ()
  92. def __init__(self,
  93. name=None,
  94. mdx=None,
  95. memberName=None,
  96. hierarchy=None,
  97. parent=None,
  98. solveOrder=None,
  99. set=None,
  100. extLst=None,
  101. ):
  102. self.name = name
  103. self.mdx = mdx
  104. self.memberName = memberName
  105. self.hierarchy = hierarchy
  106. self.parent = parent
  107. self.solveOrder = solveOrder
  108. self.set = set
  109. #self.extLst = extLst
  110. class CalculatedItem(Serialisable):
  111. tagname = "calculatedItem"
  112. field = Integer(allow_none=True)
  113. formula = String()
  114. pivotArea = Typed(expected_type=PivotArea, )
  115. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  116. __elements__ = ('pivotArea', 'extLst')
  117. def __init__(self,
  118. field=None,
  119. formula=None,
  120. pivotArea=None,
  121. extLst=None,
  122. ):
  123. self.field = field
  124. self.formula = formula
  125. self.pivotArea = pivotArea
  126. self.extLst = extLst
  127. class ServerFormat(Serialisable):
  128. tagname = "serverFormat"
  129. culture = String(allow_none=True)
  130. format = String(allow_none=True)
  131. def __init__(self,
  132. culture=None,
  133. format=None,
  134. ):
  135. self.culture = culture
  136. self.format = format
  137. class Query(Serialisable):
  138. tagname = "query"
  139. mdx = String()
  140. tpls = Typed(expected_type=TupleList, allow_none=True)
  141. __elements__ = ('tpls',)
  142. def __init__(self,
  143. mdx=None,
  144. tpls=None,
  145. ):
  146. self.mdx = mdx
  147. self.tpls = tpls
  148. class OLAPSet(Serialisable):
  149. tagname = "set"
  150. count = Integer()
  151. maxRank = Integer()
  152. setDefinition = String()
  153. sortType = NoneSet(values=(['ascending', 'descending', 'ascendingAlpha',
  154. 'descendingAlpha', 'ascendingNatural', 'descendingNatural']))
  155. queryFailed = Bool()
  156. tpls = Typed(expected_type=TupleList, allow_none=True)
  157. sortByTuple = Typed(expected_type=TupleList, allow_none=True)
  158. __elements__ = ('tpls', 'sortByTuple')
  159. def __init__(self,
  160. count=None,
  161. maxRank=None,
  162. setDefinition=None,
  163. sortType=None,
  164. queryFailed=None,
  165. tpls=None,
  166. sortByTuple=None,
  167. ):
  168. self.count = count
  169. self.maxRank = maxRank
  170. self.setDefinition = setDefinition
  171. self.sortType = sortType
  172. self.queryFailed = queryFailed
  173. self.tpls = tpls
  174. self.sortByTuple = sortByTuple
  175. class PCDSDTCEntries(Serialisable):
  176. # Implements CT_PCDSDTCEntries
  177. tagname = "entries"
  178. count = Integer(allow_none=True)
  179. # elements are choice
  180. m = Typed(expected_type=Missing, allow_none=True)
  181. n = Typed(expected_type=Number, allow_none=True)
  182. e = Typed(expected_type=Error, allow_none=True)
  183. s = Typed(expected_type=Text, allow_none=True)
  184. __elements__ = ('m', 'n', 'e', 's')
  185. def __init__(self,
  186. count=None,
  187. m=None,
  188. n=None,
  189. e=None,
  190. s=None,
  191. ):
  192. self.count = count
  193. self.m = m
  194. self.n = n
  195. self.e = e
  196. self.s = s
  197. class TupleCache(Serialisable):
  198. tagname = "tupleCache"
  199. entries = Typed(expected_type=PCDSDTCEntries, allow_none=True)
  200. sets = NestedSequence(expected_type=OLAPSet, count=True)
  201. queryCache = NestedSequence(expected_type=Query, count=True)
  202. serverFormats = NestedSequence(expected_type=ServerFormat, count=True)
  203. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  204. __elements__ = ('entries', 'sets', 'queryCache', 'serverFormats', 'extLst')
  205. def __init__(self,
  206. entries=None,
  207. sets=(),
  208. queryCache=(),
  209. serverFormats=(),
  210. extLst=None,
  211. ):
  212. self.entries = entries
  213. self.sets = sets
  214. self.queryCache = queryCache
  215. self.serverFormats = serverFormats
  216. self.extLst = extLst
  217. class OLAPKPI(Serialisable):
  218. tagname = "kpi"
  219. uniqueName = String()
  220. caption = String(allow_none=True)
  221. displayFolder = String(allow_none=True)
  222. measureGroup = String(allow_none=True)
  223. parent = String(allow_none=True)
  224. value = String()
  225. goal = String(allow_none=True)
  226. status = String(allow_none=True)
  227. trend = String(allow_none=True)
  228. weight = String(allow_none=True)
  229. time = String(allow_none=True)
  230. def __init__(self,
  231. uniqueName=None,
  232. caption=None,
  233. displayFolder=None,
  234. measureGroup=None,
  235. parent=None,
  236. value=None,
  237. goal=None,
  238. status=None,
  239. trend=None,
  240. weight=None,
  241. time=None,
  242. ):
  243. self.uniqueName = uniqueName
  244. self.caption = caption
  245. self.displayFolder = displayFolder
  246. self.measureGroup = measureGroup
  247. self.parent = parent
  248. self.value = value
  249. self.goal = goal
  250. self.status = status
  251. self.trend = trend
  252. self.weight = weight
  253. self.time = time
  254. class GroupMember(Serialisable):
  255. tagname = "groupMember"
  256. uniqueName = String()
  257. group = Bool()
  258. def __init__(self,
  259. uniqueName=None,
  260. group=None,
  261. ):
  262. self.uniqueName = uniqueName
  263. self.group = group
  264. class LevelGroup(Serialisable):
  265. tagname = "group"
  266. name = String()
  267. uniqueName = String()
  268. caption = String()
  269. uniqueParent = String()
  270. id = Integer()
  271. groupMembers = NestedSequence(expected_type=GroupMember, count=True)
  272. __elements__ = ('groupMembers',)
  273. def __init__(self,
  274. name=None,
  275. uniqueName=None,
  276. caption=None,
  277. uniqueParent=None,
  278. id=None,
  279. groupMembers=(),
  280. ):
  281. self.name = name
  282. self.uniqueName = uniqueName
  283. self.caption = caption
  284. self.uniqueParent = uniqueParent
  285. self.id = id
  286. self.groupMembers = groupMembers
  287. class GroupLevel(Serialisable):
  288. tagname = "groupLevel"
  289. uniqueName = String()
  290. caption = String()
  291. user = Bool()
  292. customRollUp = Bool()
  293. groups = NestedSequence(expected_type=LevelGroup, count=True)
  294. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  295. __elements__ = ('groups', 'extLst')
  296. def __init__(self,
  297. uniqueName=None,
  298. caption=None,
  299. user=None,
  300. customRollUp=None,
  301. groups=(),
  302. extLst=None,
  303. ):
  304. self.uniqueName = uniqueName
  305. self.caption = caption
  306. self.user = user
  307. self.customRollUp = customRollUp
  308. self.groups = groups
  309. self.extLst = extLst
  310. class FieldUsage(Serialisable):
  311. tagname = "fieldUsage"
  312. x = Integer()
  313. def __init__(self,
  314. x=None,
  315. ):
  316. self.x = x
  317. class CacheHierarchy(Serialisable):
  318. tagname = "cacheHierarchy"
  319. uniqueName = String()
  320. caption = String(allow_none=True)
  321. measure = Bool()
  322. set = Bool()
  323. parentSet = Integer(allow_none=True)
  324. iconSet = Integer()
  325. attribute = Bool()
  326. time = Bool()
  327. keyAttribute = Bool()
  328. defaultMemberUniqueName = String(allow_none=True)
  329. allUniqueName = String(allow_none=True)
  330. allCaption = String(allow_none=True)
  331. dimensionUniqueName = String(allow_none=True)
  332. displayFolder = String(allow_none=True)
  333. measureGroup = String(allow_none=True)
  334. measures = Bool()
  335. count = Integer()
  336. oneField = Bool()
  337. memberValueDatatype = Integer(allow_none=True)
  338. unbalanced = Bool(allow_none=True)
  339. unbalancedGroup = Bool(allow_none=True)
  340. hidden = Bool()
  341. fieldsUsage = NestedSequence(expected_type=FieldUsage, count=True)
  342. groupLevels = NestedSequence(expected_type=GroupLevel, count=True)
  343. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  344. __elements__ = ('fieldsUsage', 'groupLevels')
  345. def __init__(self,
  346. uniqueName="",
  347. caption=None,
  348. measure=None,
  349. set=None,
  350. parentSet=None,
  351. iconSet=0,
  352. attribute=None,
  353. time=None,
  354. keyAttribute=None,
  355. defaultMemberUniqueName=None,
  356. allUniqueName=None,
  357. allCaption=None,
  358. dimensionUniqueName=None,
  359. displayFolder=None,
  360. measureGroup=None,
  361. measures=None,
  362. count=None,
  363. oneField=None,
  364. memberValueDatatype=None,
  365. unbalanced=None,
  366. unbalancedGroup=None,
  367. hidden=None,
  368. fieldsUsage=(),
  369. groupLevels=(),
  370. extLst=None,
  371. ):
  372. self.uniqueName = uniqueName
  373. self.caption = caption
  374. self.measure = measure
  375. self.set = set
  376. self.parentSet = parentSet
  377. self.iconSet = iconSet
  378. self.attribute = attribute
  379. self.time = time
  380. self.keyAttribute = keyAttribute
  381. self.defaultMemberUniqueName = defaultMemberUniqueName
  382. self.allUniqueName = allUniqueName
  383. self.allCaption = allCaption
  384. self.dimensionUniqueName = dimensionUniqueName
  385. self.displayFolder = displayFolder
  386. self.measureGroup = measureGroup
  387. self.measures = measures
  388. self.count = count
  389. self.oneField = oneField
  390. self.memberValueDatatype = memberValueDatatype
  391. self.unbalanced = unbalanced
  392. self.unbalancedGroup = unbalancedGroup
  393. self.hidden = hidden
  394. self.fieldsUsage = fieldsUsage
  395. self.groupLevels = groupLevels
  396. self.extLst = extLst
  397. class GroupItems(Serialisable):
  398. tagname = "groupItems"
  399. m = Sequence(expected_type=Missing)
  400. n = Sequence(expected_type=Number)
  401. b = Sequence(expected_type=Boolean)
  402. e = Sequence(expected_type=Error)
  403. s = Sequence(expected_type=Text)
  404. d = Sequence(expected_type=DateTimeField,)
  405. __elements__ = ('m', 'n', 'b', 'e', 's', 'd')
  406. __attrs__ = ("count", )
  407. def __init__(self,
  408. count=None,
  409. m=(),
  410. n=(),
  411. b=(),
  412. e=(),
  413. s=(),
  414. d=(),
  415. ):
  416. self.m = m
  417. self.n = n
  418. self.b = b
  419. self.e = e
  420. self.s = s
  421. self.d = d
  422. @property
  423. def count(self):
  424. return len(self.m + self.n + self.b + self.e + self.s + self.d)
  425. class RangePr(Serialisable):
  426. tagname = "rangePr"
  427. autoStart = Bool(allow_none=True)
  428. autoEnd = Bool(allow_none=True)
  429. groupBy = NoneSet(values=(['range', 'seconds', 'minutes', 'hours', 'days',
  430. 'months', 'quarters', 'years']))
  431. startNum = Float(allow_none=True)
  432. endNum = Float(allow_none=True)
  433. startDate = DateTime(allow_none=True)
  434. endDate = DateTime(allow_none=True)
  435. groupInterval = Float(allow_none=True)
  436. def __init__(self,
  437. autoStart=True,
  438. autoEnd=True,
  439. groupBy="range",
  440. startNum=None,
  441. endNum=None,
  442. startDate=None,
  443. endDate=None,
  444. groupInterval=1,
  445. ):
  446. self.autoStart = autoStart
  447. self.autoEnd = autoEnd
  448. self.groupBy = groupBy
  449. self.startNum = startNum
  450. self.endNum = endNum
  451. self.startDate = startDate
  452. self.endDate = endDate
  453. self.groupInterval = groupInterval
  454. class FieldGroup(Serialisable):
  455. tagname = "fieldGroup"
  456. par = Integer(allow_none=True)
  457. base = Integer(allow_none=True)
  458. rangePr = Typed(expected_type=RangePr, allow_none=True)
  459. discretePr = NestedSequence(expected_type=NestedInteger, count=True)
  460. groupItems = Typed(expected_type=GroupItems, allow_none=True)
  461. __elements__ = ('rangePr', 'discretePr', 'groupItems')
  462. def __init__(self,
  463. par=None,
  464. base=None,
  465. rangePr=None,
  466. discretePr=(),
  467. groupItems=None,
  468. ):
  469. self.par = par
  470. self.base = base
  471. self.rangePr = rangePr
  472. self.discretePr = discretePr
  473. self.groupItems = groupItems
  474. class SharedItems(Serialisable):
  475. tagname = "sharedItems"
  476. _fields = MultiSequence()
  477. m = MultiSequencePart(expected_type=Missing, store="_fields")
  478. n = MultiSequencePart(expected_type=Number, store="_fields")
  479. b = MultiSequencePart(expected_type=Boolean, store="_fields")
  480. e = MultiSequencePart(expected_type=Error, store="_fields")
  481. s = MultiSequencePart(expected_type=Text, store="_fields")
  482. d = MultiSequencePart(expected_type=DateTimeField, store="_fields")
  483. # attributes are optional and must be derived from associated cache records
  484. containsSemiMixedTypes = Bool(allow_none=True)
  485. containsNonDate = Bool(allow_none=True)
  486. containsDate = Bool(allow_none=True)
  487. containsString = Bool(allow_none=True)
  488. containsBlank = Bool(allow_none=True)
  489. containsMixedTypes = Bool(allow_none=True)
  490. containsNumber = Bool(allow_none=True)
  491. containsInteger = Bool(allow_none=True)
  492. minValue = Float(allow_none=True)
  493. maxValue = Float(allow_none=True)
  494. minDate = DateTime(allow_none=True)
  495. maxDate = DateTime(allow_none=True)
  496. longText = Bool(allow_none=True)
  497. __attrs__ = ('count', 'containsBlank', 'containsDate', 'containsInteger',
  498. 'containsMixedTypes', 'containsNonDate', 'containsNumber',
  499. 'containsSemiMixedTypes', 'containsString', 'minValue', 'maxValue',
  500. 'minDate', 'maxDate', 'longText')
  501. def __init__(self,
  502. _fields=(),
  503. containsSemiMixedTypes=None,
  504. containsNonDate=None,
  505. containsDate=None,
  506. containsString=None,
  507. containsBlank=None,
  508. containsMixedTypes=None,
  509. containsNumber=None,
  510. containsInteger=None,
  511. minValue=None,
  512. maxValue=None,
  513. minDate=None,
  514. maxDate=None,
  515. count=None,
  516. longText=None,
  517. ):
  518. self._fields = _fields
  519. self.containsBlank = containsBlank
  520. self.containsDate = containsDate
  521. self.containsNonDate = containsNonDate
  522. self.containsString = containsString
  523. self.containsMixedTypes = containsMixedTypes
  524. self.containsSemiMixedTypes = containsSemiMixedTypes
  525. self.containsNumber = containsNumber
  526. self.containsInteger = containsInteger
  527. self.minValue = minValue
  528. self.maxValue = maxValue
  529. self.minDate = minDate
  530. self.maxDate = maxDate
  531. self.longText = longText
  532. @property
  533. def count(self):
  534. return len(self._fields)
  535. class CacheField(Serialisable):
  536. tagname = "cacheField"
  537. sharedItems = Typed(expected_type=SharedItems, allow_none=True)
  538. fieldGroup = Typed(expected_type=FieldGroup, allow_none=True)
  539. mpMap = NestedInteger(allow_none=True, attribute="v")
  540. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  541. name = String()
  542. caption = String(allow_none=True)
  543. propertyName = String(allow_none=True)
  544. serverField = Bool(allow_none=True)
  545. uniqueList = Bool(allow_none=True)
  546. numFmtId = Integer(allow_none=True)
  547. formula = String(allow_none=True)
  548. sqlType = Integer(allow_none=True)
  549. hierarchy = Integer(allow_none=True)
  550. level = Integer(allow_none=True)
  551. databaseField = Bool(allow_none=True)
  552. mappingCount = Integer(allow_none=True)
  553. memberPropertyField = Bool(allow_none=True)
  554. __elements__ = ('sharedItems', 'fieldGroup', 'mpMap')
  555. def __init__(self,
  556. sharedItems=None,
  557. fieldGroup=None,
  558. mpMap=None,
  559. extLst=None,
  560. name=None,
  561. caption=None,
  562. propertyName=None,
  563. serverField=None,
  564. uniqueList=True,
  565. numFmtId=None,
  566. formula=None,
  567. sqlType=0,
  568. hierarchy=0,
  569. level=0,
  570. databaseField=True,
  571. mappingCount=None,
  572. memberPropertyField=None,
  573. ):
  574. self.sharedItems = sharedItems
  575. self.fieldGroup = fieldGroup
  576. self.mpMap = mpMap
  577. self.extLst = extLst
  578. self.name = name
  579. self.caption = caption
  580. self.propertyName = propertyName
  581. self.serverField = serverField
  582. self.uniqueList = uniqueList
  583. self.numFmtId = numFmtId
  584. self.formula = formula
  585. self.sqlType = sqlType
  586. self.hierarchy = hierarchy
  587. self.level = level
  588. self.databaseField = databaseField
  589. self.mappingCount = mappingCount
  590. self.memberPropertyField = memberPropertyField
  591. class RangeSet(Serialisable):
  592. tagname = "rangeSet"
  593. i1 = Integer(allow_none=True)
  594. i2 = Integer(allow_none=True)
  595. i3 = Integer(allow_none=True)
  596. i4 = Integer(allow_none=True)
  597. ref = String()
  598. name = String(allow_none=True)
  599. sheet = String(allow_none=True)
  600. def __init__(self,
  601. i1=None,
  602. i2=None,
  603. i3=None,
  604. i4=None,
  605. ref=None,
  606. name=None,
  607. sheet=None,
  608. ):
  609. self.i1 = i1
  610. self.i2 = i2
  611. self.i3 = i3
  612. self.i4 = i4
  613. self.ref = ref
  614. self.name = name
  615. self.sheet = sheet
  616. class PageItem(Serialisable):
  617. tagname = "pageItem"
  618. name = String()
  619. def __init__(self,
  620. name=None,
  621. ):
  622. self.name = name
  623. class Consolidation(Serialisable):
  624. tagname = "consolidation"
  625. autoPage = Bool(allow_none=True)
  626. pages = NestedSequence(expected_type=PageItem, count=True)
  627. rangeSets = NestedSequence(expected_type=RangeSet, count=True)
  628. __elements__ = ('pages', 'rangeSets')
  629. def __init__(self,
  630. autoPage=None,
  631. pages=(),
  632. rangeSets=(),
  633. ):
  634. self.autoPage = autoPage
  635. self.pages = pages
  636. self.rangeSets = rangeSets
  637. class WorksheetSource(Serialisable):
  638. tagname = "worksheetSource"
  639. ref = String(allow_none=True)
  640. name = String(allow_none=True)
  641. sheet = String(allow_none=True)
  642. def __init__(self,
  643. ref=None,
  644. name=None,
  645. sheet=None,
  646. ):
  647. self.ref = ref
  648. self.name = name
  649. self.sheet = sheet
  650. class CacheSource(Serialisable):
  651. tagname = "cacheSource"
  652. type = Set(values=(['worksheet', 'external', 'consolidation', 'scenario']))
  653. connectionId = Integer(allow_none=True)
  654. # some elements are choice
  655. worksheetSource = Typed(expected_type=WorksheetSource, allow_none=True)
  656. consolidation = Typed(expected_type=Consolidation, allow_none=True)
  657. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  658. __elements__ = ('worksheetSource', 'consolidation',)
  659. def __init__(self,
  660. type=None,
  661. connectionId=None,
  662. worksheetSource=None,
  663. consolidation=None,
  664. extLst=None,
  665. ):
  666. self.type = type
  667. self.connectionId = connectionId
  668. self.worksheetSource = worksheetSource
  669. self.consolidation = consolidation
  670. class CacheDefinition(Serialisable):
  671. mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
  672. rel_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
  673. _id = 1
  674. _path = "/xl/pivotCache/pivotCacheDefinition{0}.xml"
  675. records = None
  676. tagname = "pivotCacheDefinition"
  677. invalid = Bool(allow_none=True)
  678. saveData = Bool(allow_none=True)
  679. refreshOnLoad = Bool(allow_none=True)
  680. optimizeMemory = Bool(allow_none=True)
  681. enableRefresh = Bool(allow_none=True)
  682. refreshedBy = String(allow_none=True)
  683. refreshedDate = Float(allow_none=True)
  684. refreshedDateIso = DateTime(allow_none=True)
  685. backgroundQuery = Bool(allow_none=True)
  686. missingItemsLimit = Integer(allow_none=True)
  687. createdVersion = Integer(allow_none=True)
  688. refreshedVersion = Integer(allow_none=True)
  689. minRefreshableVersion = Integer(allow_none=True)
  690. recordCount = Integer(allow_none=True)
  691. upgradeOnRefresh = Bool(allow_none=True)
  692. supportSubquery = Bool(allow_none=True)
  693. supportAdvancedDrill = Bool(allow_none=True)
  694. cacheSource = Typed(expected_type=CacheSource)
  695. cacheFields = NestedSequence(expected_type=CacheField, count=True)
  696. cacheHierarchies = NestedSequence(expected_type=CacheHierarchy, allow_none=True)
  697. kpis = NestedSequence(expected_type=OLAPKPI, count=True)
  698. tupleCache = Typed(expected_type=TupleCache, allow_none=True)
  699. calculatedItems = NestedSequence(expected_type=CalculatedItem, count=True)
  700. calculatedMembers = NestedSequence(expected_type=CalculatedMember, count=True)
  701. dimensions = NestedSequence(expected_type=PivotDimension, allow_none=True)
  702. measureGroups = NestedSequence(expected_type=MeasureGroup, count=True)
  703. maps = NestedSequence(expected_type=MeasureDimensionMap, count=True)
  704. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  705. id = Relation()
  706. __elements__ = ('cacheSource', 'cacheFields', 'cacheHierarchies', 'kpis',
  707. 'tupleCache', 'calculatedItems', 'calculatedMembers', 'dimensions',
  708. 'measureGroups', 'maps',)
  709. def __init__(self,
  710. invalid=None,
  711. saveData=None,
  712. refreshOnLoad=None,
  713. optimizeMemory=None,
  714. enableRefresh=None,
  715. refreshedBy=None,
  716. refreshedDate=None,
  717. refreshedDateIso=None,
  718. backgroundQuery=None,
  719. missingItemsLimit=None,
  720. createdVersion=None,
  721. refreshedVersion=None,
  722. minRefreshableVersion=None,
  723. recordCount=None,
  724. upgradeOnRefresh=None,
  725. tupleCache=None,
  726. supportSubquery=None,
  727. supportAdvancedDrill=None,
  728. cacheSource=None,
  729. cacheFields=(),
  730. cacheHierarchies=(),
  731. kpis=(),
  732. calculatedItems=(),
  733. calculatedMembers=(),
  734. dimensions=(),
  735. measureGroups=(),
  736. maps=(),
  737. extLst=None,
  738. id = None,
  739. ):
  740. self.invalid = invalid
  741. self.saveData = saveData
  742. self.refreshOnLoad = refreshOnLoad
  743. self.optimizeMemory = optimizeMemory
  744. self.enableRefresh = enableRefresh
  745. self.refreshedBy = refreshedBy
  746. self.refreshedDate = refreshedDate
  747. self.refreshedDateIso = refreshedDateIso
  748. self.backgroundQuery = backgroundQuery
  749. self.missingItemsLimit = missingItemsLimit
  750. self.createdVersion = createdVersion
  751. self.refreshedVersion = refreshedVersion
  752. self.minRefreshableVersion = minRefreshableVersion
  753. self.recordCount = recordCount
  754. self.upgradeOnRefresh = upgradeOnRefresh
  755. self.supportSubquery = supportSubquery
  756. self.supportAdvancedDrill = supportAdvancedDrill
  757. self.cacheSource = cacheSource
  758. self.cacheFields = cacheFields
  759. self.cacheHierarchies = cacheHierarchies
  760. self.kpis = kpis
  761. self.tupleCache = tupleCache
  762. self.calculatedItems = calculatedItems
  763. self.calculatedMembers = calculatedMembers
  764. self.dimensions = dimensions
  765. self.measureGroups = measureGroups
  766. self.maps = maps
  767. self.id = id
  768. def to_tree(self):
  769. node = super().to_tree()
  770. node.set("xmlns", SHEET_MAIN_NS)
  771. return node
  772. @property
  773. def path(self):
  774. return self._path.format(self._id)
  775. def _write(self, archive, manifest):
  776. """
  777. Add to zipfile and update manifest
  778. """
  779. self._write_rels(archive, manifest)
  780. xml = tostring(self.to_tree())
  781. archive.writestr(self.path[1:], xml)
  782. manifest.append(self)
  783. def _write_rels(self, archive, manifest):
  784. """
  785. Write the relevant child objects and add links
  786. """
  787. if self.records is None:
  788. return
  789. rels = RelationshipList()
  790. r = Relationship(Type=self.records.rel_type, Target=self.records.path)
  791. rels.append(r)
  792. self.id = r.id
  793. self.records._id = self._id
  794. self.records._write(archive, manifest)
  795. path = get_rels_path(self.path)
  796. xml = tostring(rels.to_tree())
  797. archive.writestr(path[1:], xml)