1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# Copyright (c) 2010-2024 openpyxl
from openpyxl.descriptors.serialisable import Serialisable
from openpyxl.descriptors import (
Typed,
Integer,
Sequence,
)
from openpyxl.descriptors.sequence import (
MultiSequence,
MultiSequencePart,
)
from openpyxl.descriptors.excel import ExtensionList
from openpyxl.descriptors.nested import (
NestedInteger,
NestedBool,
)
from openpyxl.xml.constants import SHEET_MAIN_NS
from openpyxl.xml.functions import tostring
from .fields import (
Boolean,
Error,
Missing,
Number,
Text,
TupleList,
DateTimeField,
Index,
)
class Record(Serialisable):
tagname = "r"
_fields = MultiSequence()
m = MultiSequencePart(expected_type=Missing, store="_fields")
n = MultiSequencePart(expected_type=Number, store="_fields")
b = MultiSequencePart(expected_type=Boolean, store="_fields")
e = MultiSequencePart(expected_type=Error, store="_fields")
s = MultiSequencePart(expected_type=Text, store="_fields")
d = MultiSequencePart(expected_type=DateTimeField, store="_fields")
x = MultiSequencePart(expected_type=Index, store="_fields")
def __init__(self,
_fields=(),
m=None,
n=None,
b=None,
e=None,
s=None,
d=None,
x=None,
):
self._fields = _fields
class RecordList(Serialisable):
mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
rel_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords"
_id = 1
_path = "/xl/pivotCache/pivotCacheRecords{0}.xml"
tagname ="pivotCacheRecords"
r = Sequence(expected_type=Record, allow_none=True)
extLst = Typed(expected_type=ExtensionList, allow_none=True)
__elements__ = ('r', )
__attrs__ = ('count', )
def __init__(self,
count=None,
r=(),
extLst=None,
):
self.r = r
self.extLst = extLst
@property
def count(self):
return len(self.r)
def to_tree(self):
tree = super().to_tree()
tree.set("xmlns", SHEET_MAIN_NS)
return tree
@property
def path(self):
return self._path.format(self._id)
def _write(self, archive, manifest):
"""
Write to zipfile and update manifest
"""
xml = tostring(self.to_tree())
archive.writestr(self.path[1:], xml)
manifest.append(self)
def _write_rels(self, archive, manifest):
pass
|