Class JsonCustomProps
- class ooodev.io.json.JsonCustomProps(doc, file_name='DocumentCustomProperties.json')[source]
Class to add custom properties to a document. The properties are stored in a json file embedded in the document.
Allows custom properties to be added to a document.
Note
Any value that can be serialized to JSON can be stored as a custom property. Classes can implement the
ooodev.io.json.json_encoder.JsonEncoder
class to provide custom serialization by overriding theon_json_encode()
method.- Parameters:
doc (OfficeDocumentT) –
file_name (str) –
- __init__(doc, file_name='DocumentCustomProperties.json')[source]
Constructor.
- Parameters:
doc (Any) – The document.
file_name (str, optional) – The name of the file to store the properties. Defaults to “DocumentCustomProperties.json”.
- get_custom_properties()[source]
Gets custom properties.
- Returns:
custom properties.
- Return type:
DotDict
Hint
DotDict is a class that allows you to access dictionary keys as attributes or keys. DotDict can be imported from
ooodev.utils.helper.dot_dict.DotDict
.
- get_custom_property(name, default=<object object>)[source]
Gets a custom property.
- Parameters:
name (str) – The name of the property.
default (Any, optional) – The default value to return if the property does not exist.
- Raises:
AttributeError – If the property is not found.
- Returns:
The value of the property.
- Return type:
Any
- has_custom_property(name)[source]
Gets if a custom property exists.
- Parameters:
name (str) – The name of the property to check.
- Returns:
True
if the property exists, otherwiseFalse
.- Return type:
bool
- remove_custom_property(name)[source]
Removes a custom property.
- Parameters:
name (str) – The name of the property to remove.
- Raises:
AttributeError – If the property is a forbidden key.
- Return type:
None
- set_custom_properties(properties)[source]
Sets custom properties.
- Parameters:
properties (DotDict) – custom properties to set.
- Return type:
None
Hint
DotDict is a class that allows you to access dictionary keys as attributes or keys. DotDict can be imported from
ooodev.utils.helper.dot_dict.DotDict
.- Return type:
None
- Parameters:
properties (DotDict) –