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

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

22 statements  

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

2# 

3# RichValueRel - A class for writing the Excel XLSX richValueRel.xml file. 

4# 

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

6# 

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

8# 

9 

10# Package imports. 

11from . import xmlwriter 

12 

13 

14class RichValueRel(xmlwriter.XMLwriter): 

15 """ 

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

17 

18 

19 """ 

20 

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

22 # 

23 # Public API. 

24 # 

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

26 

27 def __init__(self): 

28 """ 

29 Constructor. 

30 

31 """ 

32 

33 super().__init__() 

34 self.num_embedded_images = 0 

35 

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

37 # 

38 # Private API. 

39 # 

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

41 

42 def _assemble_xml_file(self): 

43 # Assemble and write the XML file. 

44 

45 # Write the XML declaration. 

46 self._xml_declaration() 

47 

48 # Write the richValueRels element. 

49 self._write_rich_value_rels() 

50 

51 self._xml_end_tag("richValueRels") 

52 

53 # Close the file. 

54 self._xml_close() 

55 

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

57 # 

58 # XML methods. 

59 # 

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

61 def _write_rich_value_rels(self): 

62 # Write the <richValueRels> element. 

63 xmlns = "http://schemas.microsoft.com/office/spreadsheetml/2022/richvaluerel" 

64 xmlns_r = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" 

65 

66 attributes = [ 

67 ("xmlns", xmlns), 

68 ("xmlns:r", xmlns_r), 

69 ] 

70 

71 self._xml_start_tag("richValueRels", attributes) 

72 

73 # Write the rel elements. 

74 for index in range(self.num_embedded_images): 

75 self._write_rel(index + 1) 

76 

77 def _write_rel(self, index): 

78 # Write the <rel> element. 

79 r_id = f"rId{index}" 

80 attributes = [("r:id", r_id)] 

81 

82 self._xml_empty_tag("rel", attributes)