Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/xlsxwriter/rich_value.py: 24%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###############################################################################
2#
3# RichValue - A class for writing the Excel XLSX rdrichvalue.xml file.
4#
5# SPDX-License-Identifier: BSD-2-Clause
6# Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7#
9# Package imports.
10from . import xmlwriter
13class RichValue(xmlwriter.XMLwriter):
14 """
15 A class for writing the Excel XLSX rdrichvalue.xml file.
18 """
20 ###########################################################################
21 #
22 # Public API.
23 #
24 ###########################################################################
26 def __init__(self):
27 """
28 Constructor.
30 """
32 super(RichValue, self).__init__()
33 self.embedded_images = []
35 ###########################################################################
36 #
37 # Private API.
38 #
39 ###########################################################################
41 def _assemble_xml_file(self):
42 # Assemble and write the XML file.
44 # Write the XML declaration.
45 self._xml_declaration()
47 # Write the rvData element.
48 self._write_rv_data()
50 self._xml_end_tag("rvData")
52 # Close the file.
53 self._xml_close()
55 ###########################################################################
56 #
57 # XML methods.
58 #
59 ###########################################################################
60 def _write_rv_data(self):
61 # Write the <rvData> element.
62 xmlns = "http://schemas.microsoft.com/office/spreadsheetml/2017/richdata"
64 attributes = [
65 ("xmlns", xmlns),
66 ("count", len(self.embedded_images)),
67 ]
69 self._xml_start_tag("rvData", attributes)
71 for index, image_data in enumerate(self.embedded_images):
72 # Write the rv element.
73 self._write_rv(index, image_data[3], image_data[4])
75 def _write_rv(self, index, description, decorative):
76 # Write the <rv> element.
77 attributes = [("s", 0)]
78 value = 5
80 if decorative:
81 value = 6
83 self._xml_start_tag("rv", attributes)
85 # Write the v elements.
86 self._write_v(index)
87 self._write_v(value)
89 if description:
90 self._write_v(description)
92 self._xml_end_tag("rv")
94 def _write_v(self, data):
95 # Write the <v> element.
96 self._xml_data_element("v", data)