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

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

21 statements  

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

2# 

3# RichValueRel - A class for writing the Excel XLSX richValueRel.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 RichValueRel(xmlwriter.XMLwriter): 

14 """ 

15 A class for writing the Excel XLSX richValueRel.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(RichValueRel, self).__init__() 

33 self.num_embedded_images = 0 

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 richValueRels element. 

48 self._write_rich_value_rels() 

49 

50 self._xml_end_tag("richValueRels") 

51 

52 # Close the file. 

53 self._xml_close() 

54 

55 ########################################################################### 

56 # 

57 # XML methods. 

58 # 

59 ########################################################################### 

60 def _write_rich_value_rels(self): 

61 # Write the <richValueRels> element. 

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

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

64 

65 attributes = [ 

66 ("xmlns", xmlns), 

67 ("xmlns:r", xmlns_r), 

68 ] 

69 

70 self._xml_start_tag("richValueRels", attributes) 

71 

72 # Write the rel elements. 

73 for index in range(self.num_embedded_images): 

74 self._write_rel(index + 1) 

75 

76 def _write_rel(self, index): 

77 # Write the <rel> element. 

78 r_id = f"rId{index}" 

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

80 

81 self._xml_empty_tag("rel", attributes)