Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/xlsxwriter/rich_value.py: 26%

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

31 statements  

1############################################################################### 

2# 

3# RichValue - A class for writing the Excel XLSX rdrichvalue.xml file. 

4# 

5# SPDX-License-Identifier: BSD-2-Clause 

6# 

7# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org 

8# 

9 

10from xlsxwriter import xmlwriter 

11from xlsxwriter.image import Image 

12 

13 

14class RichValue(xmlwriter.XMLwriter): 

15 """ 

16 A class for writing the Excel XLSX rdrichvalue.xml file. 

17 

18 

19 """ 

20 

21 ########################################################################### 

22 # 

23 # Public API. 

24 # 

25 ########################################################################### 

26 

27 def __init__(self) -> None: 

28 """ 

29 Constructor. 

30 

31 """ 

32 

33 super().__init__() 

34 self.embedded_images = [] 

35 

36 ########################################################################### 

37 # 

38 # Private API. 

39 # 

40 ########################################################################### 

41 

42 def _assemble_xml_file(self) -> None: 

43 # Assemble and write the XML file. 

44 

45 # Write the XML declaration. 

46 self._xml_declaration() 

47 

48 # Write the rvData element. 

49 self._write_rv_data() 

50 

51 self._xml_end_tag("rvData") 

52 

53 # Close the file. 

54 self._xml_close() 

55 

56 ########################################################################### 

57 # 

58 # XML methods. 

59 # 

60 ########################################################################### 

61 def _write_rv_data(self) -> None: 

62 # Write the <rvData> element. 

63 xmlns = "http://schemas.microsoft.com/office/spreadsheetml/2017/richdata" 

64 

65 attributes = [ 

66 ("xmlns", xmlns), 

67 ("count", len(self.embedded_images)), 

68 ] 

69 

70 self._xml_start_tag("rvData", attributes) 

71 

72 for index, image in enumerate(self.embedded_images): 

73 # Write the rv element. 

74 self._write_rv(index, image) 

75 

76 def _write_rv(self, index, image: Image) -> None: 

77 # Write the <rv> element. 

78 attributes = [("s", 0)] 

79 value = 5 

80 

81 if image.decorative: 

82 value = 6 

83 

84 self._xml_start_tag("rv", attributes) 

85 

86 # Write the v elements. 

87 self._write_v(index) 

88 self._write_v(value) 

89 

90 if image.description: 

91 self._write_v(image.description) 

92 

93 self._xml_end_tag("rv") 

94 

95 def _write_v(self, data) -> None: 

96 # Write the <v> element. 

97 self._xml_data_element("v", data)