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
|
###############################################################################
#
# RichValue - A class for writing the Excel XLSX rdrichvalue.xml file.
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org
#
# Package imports.
from . import xmlwriter
class RichValue(xmlwriter.XMLwriter):
"""
A class for writing the Excel XLSX rdrichvalue.xml file.
"""
###########################################################################
#
# Public API.
#
###########################################################################
def __init__(self):
"""
Constructor.
"""
super().__init__()
self.embedded_images = []
###########################################################################
#
# Private API.
#
###########################################################################
def _assemble_xml_file(self):
# Assemble and write the XML file.
# Write the XML declaration.
self._xml_declaration()
# Write the rvData element.
self._write_rv_data()
self._xml_end_tag("rvData")
# Close the file.
self._xml_close()
###########################################################################
#
# XML methods.
#
###########################################################################
def _write_rv_data(self):
# Write the <rvData> element.
xmlns = "http://schemas.microsoft.com/office/spreadsheetml/2017/richdata"
attributes = [
("xmlns", xmlns),
("count", len(self.embedded_images)),
]
self._xml_start_tag("rvData", attributes)
for index, image_data in enumerate(self.embedded_images):
# Write the rv element.
self._write_rv(index, image_data[3], image_data[4])
def _write_rv(self, index, description, decorative):
# Write the <rv> element.
attributes = [("s", 0)]
value = 5
if decorative:
value = 6
self._xml_start_tag("rv", attributes)
# Write the v elements.
self._write_v(index)
self._write_v(value)
if description:
self._write_v(description)
self._xml_end_tag("rv")
def _write_v(self, data):
# Write the <v> element.
self._xml_data_element("v", data)
|