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

29 statements  

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# 

8 

9# Package imports. 

10from . import xmlwriter 

11 

12 

13class RichValue(xmlwriter.XMLwriter): 

14 """ 

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

16 

17 

18 """ 

19 

20 ########################################################################### 

21 # 

22 # Public API. 

23 # 

24 ########################################################################### 

25 

26 def __init__(self): 

27 """ 

28 Constructor. 

29 

30 """ 

31 

32 super(RichValue, self).__init__() 

33 self.embedded_images = [] 

34 

35 ########################################################################### 

36 # 

37 # Private API. 

38 # 

39 ########################################################################### 

40 

41 def _assemble_xml_file(self): 

42 # Assemble and write the XML file. 

43 

44 # Write the XML declaration. 

45 self._xml_declaration() 

46 

47 # Write the rvData element. 

48 self._write_rv_data() 

49 

50 self._xml_end_tag("rvData") 

51 

52 # Close the file. 

53 self._xml_close() 

54 

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" 

63 

64 attributes = [ 

65 ("xmlns", xmlns), 

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

67 ] 

68 

69 self._xml_start_tag("rvData", attributes) 

70 

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]) 

74 

75 def _write_rv(self, index, description, decorative): 

76 # Write the <rv> element. 

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

78 value = 5 

79 

80 if decorative: 

81 value = 6 

82 

83 self._xml_start_tag("rv", attributes) 

84 

85 # Write the v elements. 

86 self._write_v(index) 

87 self._write_v(value) 

88 

89 if description: 

90 self._write_v(description) 

91 

92 self._xml_end_tag("rv") 

93 

94 def _write_v(self, data): 

95 # Write the <v> element. 

96 self._xml_data_element("v", data)