|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# FeaturePropertyBag - A class for writing the Excel XLSX featurePropertyBag.xml |
| 4 | +# file. |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: BSD-2-Clause |
| 7 | +# |
| 8 | +# Copyright (c) 2013-2025, John McNamara, [email protected] |
| 9 | +# |
| 10 | + |
| 11 | +# Package imports. |
| 12 | +from . import xmlwriter |
| 13 | + |
| 14 | + |
| 15 | +class FeaturePropertyBag(xmlwriter.XMLwriter): |
| 16 | + """ |
| 17 | + A class for writing the Excel XLSX FeaturePropertyBag file. |
| 18 | +
|
| 19 | +
|
| 20 | + """ |
| 21 | + |
| 22 | + ########################################################################### |
| 23 | + # |
| 24 | + # Private API. |
| 25 | + # |
| 26 | + ########################################################################### |
| 27 | + |
| 28 | + def _assemble_xml_file(self): |
| 29 | + # Assemble and write the XML file. |
| 30 | + |
| 31 | + # Write the XML declaration. |
| 32 | + self._xml_declaration() |
| 33 | + |
| 34 | + # Write the FeaturePropertyBags element. |
| 35 | + self._write_feature_property_bags() |
| 36 | + |
| 37 | + # Write the Checkbox bag element. |
| 38 | + self._write_checkbox_bag() |
| 39 | + |
| 40 | + # Write the XFControls bag element. |
| 41 | + self._write_xf_control_bag() |
| 42 | + |
| 43 | + # Write the XFComplement bag element. |
| 44 | + self._write_xf_compliment_bag() |
| 45 | + |
| 46 | + # Write the XFComplements bag element. |
| 47 | + self._write_xf_compliments_bag() |
| 48 | + |
| 49 | + self._xml_end_tag("FeaturePropertyBags") |
| 50 | + |
| 51 | + # Close the file. |
| 52 | + self._xml_close() |
| 53 | + |
| 54 | + ########################################################################### |
| 55 | + # |
| 56 | + # XML methods. |
| 57 | + # |
| 58 | + ########################################################################### |
| 59 | + |
| 60 | + def _write_feature_property_bags(self): |
| 61 | + # Write the <FeaturePropertyBags> element. |
| 62 | + |
| 63 | + xmlns = ( |
| 64 | + "http://schemas.microsoft.com/office/spreadsheetml/2022/featurepropertybag" |
| 65 | + ) |
| 66 | + |
| 67 | + attributes = [("xmlns", xmlns)] |
| 68 | + |
| 69 | + self._xml_start_tag("FeaturePropertyBags", attributes) |
| 70 | + |
| 71 | + def _write_checkbox_bag(self): |
| 72 | + # Write the Checkbox <bag> element. |
| 73 | + attributes = [("type", "Checkbox")] |
| 74 | + |
| 75 | + self._xml_empty_tag("bag", attributes) |
| 76 | + |
| 77 | + def _write_xf_control_bag(self): |
| 78 | + # Write the XFControls<bag> element. |
| 79 | + attributes = [("type", "XFControls")] |
| 80 | + |
| 81 | + self._xml_start_tag("bag", attributes) |
| 82 | + |
| 83 | + # Write the bagId element. |
| 84 | + self._write_bag_id("CellControl", 0) |
| 85 | + |
| 86 | + self._xml_end_tag("bag") |
| 87 | + |
| 88 | + def _write_xf_compliment_bag(self): |
| 89 | + # Write the XFComplement <bag> element. |
| 90 | + attributes = [("type", "XFComplement")] |
| 91 | + |
| 92 | + self._xml_start_tag("bag", attributes) |
| 93 | + |
| 94 | + # Write the bagId element. |
| 95 | + self._write_bag_id("XFControls", 1) |
| 96 | + |
| 97 | + self._xml_end_tag("bag") |
| 98 | + |
| 99 | + def _write_xf_compliments_bag(self): |
| 100 | + # Write the _write_xf_compliment_bag<bag> element. |
| 101 | + attributes = [ |
| 102 | + ("type", "XFComplements"), |
| 103 | + ("extRef", "XFComplementsMapperExtRef"), |
| 104 | + ] |
| 105 | + |
| 106 | + self._xml_start_tag("bag", attributes) |
| 107 | + self._xml_start_tag("a", [("k", "MappedFeaturePropertyBags")]) |
| 108 | + |
| 109 | + self._write_bag_id("", 2) |
| 110 | + |
| 111 | + self._xml_end_tag("a") |
| 112 | + self._xml_end_tag("bag") |
| 113 | + |
| 114 | + def _write_bag_id(self, key, bag_id): |
| 115 | + # Write the <bagId> element. |
| 116 | + attributes = [] |
| 117 | + |
| 118 | + if key: |
| 119 | + attributes = [("k", key)] |
| 120 | + |
| 121 | + self._xml_data_element("bagId", bag_id, attributes) |
0 commit comments