Skip to content

Body

Body, root of the document content.

Classes:

Name Description
Body

Root of the document content, “office:body”.

Chart

Root of the Chart document content, “office:chart”.

Database

Root of the Database document content, “office:database”.

Drawing

Root of the Drawing document content, “office:drawing”.

Image

Root of the Image document content, “office:image”.

Metadata

Root of the Meta document content, “office:meta”.

OfficeSettings

Root of the Settings document content, “office:settings”.

Presentation

Root of the Presentation document content, “office:presentation”.

Spreadsheet

Root of the Spreadsheet document content, “office:spreadsheet”.

Text

Root of the Text document content, “office:text”.

Attributes:

Name Type Description
BODY_NR_TAGS

BODY_NR_TAGS module-attribute

BODY_NR_TAGS = BODY_ALLOW_NAMED_RANGE_TAGS

Body

Bases: Element

Root of the document content, “office:body”.

Methods:

Name Description
get_table

Return the table that matches the criteria.

get_tables

Return all the tables that match the criteria.

Attributes:

Name Type Description
allow_named_range bool

Return True if the current body allows named ranges.

get_sheet
get_sheets
sheets
tables list[Table]

Return all the tables.

Source code in odfdo/body.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
class Body(Element):
    """Root of the document content, "office:body"."""

    _tag: str = "office:body"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

    def get_tables(
        self,
        style: str | None = None,
        content: str | None = None,
    ) -> list[Table]:
        """Return all the tables that match the criteria.

        The method is also accessible via the alias `get_sheets()`.

        Args:
            style: The style name of the tables to match.
            content: A regex pattern to match within the table content.

        Returns:
            list[Table]: A list of matching Table elements.
        """
        return self._filtered_elements(  # type: ignore[return-value]
            "descendant::table:table",
            table_style=style,
            content=content,
        )

    get_sheets = get_tables

    @property
    def tables(self) -> list[Table]:
        """Return all the tables.

        The property is also accessible via the alias `sheets`.

        Returns:
            list[Table]: A list of all Table elements.
        """
        return cast(list[Table], self.get_elements("descendant::table:table"))

    sheets = tables

    def get_table(
        self,
        position: int = 0,
        name: str | None = None,
        content: str | None = None,
    ) -> Table | None:
        """Return the table that matches the criteria.

        The method is also accessible via the alias `get_sheet()`.

        Args:
            position: The 0-based index of the table to retrieve
                among the matching tables. Defaults to 0.
            name: The name of the table to match.
            content: A regex pattern to match within the table content.

        Returns:
            Table or None: The matching Table element, or None if not found.
        """
        if name is None and content is None:
            result = self._filtered_element("descendant::table:table", position)
        else:
            result = self._filtered_element(
                "descendant::table:table",
                position,
                table_name=name,
                content=content,
            )
        return result  # type: ignore[return-value]

    get_sheet = get_table

    @property
    def allow_named_range(self) -> bool:
        """Return True if the current body allows named ranges."""
        return self.tag in BODY_ALLOW_NAMED_RANGE_TAGS

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:body'

allow_named_range property

allow_named_range: bool

Return True if the current body allows named ranges.

get_sheet class-attribute instance-attribute

get_sheet = get_table

get_sheets class-attribute instance-attribute

get_sheets = get_tables

sheets class-attribute instance-attribute

sheets = tables

tables property

tables: list[Table]

Return all the tables.

The property is also accessible via the alias sheets.

Returns:

Type Description
list[Table]

list[Table]: A list of all Table elements.

get_table

get_table(
    position: int = 0,
    name: str | None = None,
    content: str | None = None,
) -> Table | None

Return the table that matches the criteria.

The method is also accessible via the alias get_sheet().

Parameters:

Name Type Description Default
position int

The 0-based index of the table to retrieve among the matching tables. Defaults to 0.

0
name str | None

The name of the table to match.

None
content str | None

A regex pattern to match within the table content.

None

Returns:

Type Description
Table | None

Table or None: The matching Table element, or None if not found.

Source code in odfdo/body.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def get_table(
    self,
    position: int = 0,
    name: str | None = None,
    content: str | None = None,
) -> Table | None:
    """Return the table that matches the criteria.

    The method is also accessible via the alias `get_sheet()`.

    Args:
        position: The 0-based index of the table to retrieve
            among the matching tables. Defaults to 0.
        name: The name of the table to match.
        content: A regex pattern to match within the table content.

    Returns:
        Table or None: The matching Table element, or None if not found.
    """
    if name is None and content is None:
        result = self._filtered_element("descendant::table:table", position)
    else:
        result = self._filtered_element(
            "descendant::table:table",
            position,
            table_name=name,
            content=content,
        )
    return result  # type: ignore[return-value]

get_tables

get_tables(
    style: str | None = None, content: str | None = None
) -> list[Table]

Return all the tables that match the criteria.

The method is also accessible via the alias get_sheets().

Parameters:

Name Type Description Default
style str | None

The style name of the tables to match.

None
content str | None

A regex pattern to match within the table content.

None

Returns:

Type Description
list[Table]

list[Table]: A list of matching Table elements.

Source code in odfdo/body.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def get_tables(
    self,
    style: str | None = None,
    content: str | None = None,
) -> list[Table]:
    """Return all the tables that match the criteria.

    The method is also accessible via the alias `get_sheets()`.

    Args:
        style: The style name of the tables to match.
        content: A regex pattern to match within the table content.

    Returns:
        list[Table]: A list of matching Table elements.
    """
    return self._filtered_elements(  # type: ignore[return-value]
        "descendant::table:table",
        table_style=style,
        content=content,
    )

Chart

Bases: UserFieldDeclContMixin, VarDeclMixin, NRMixin, Body

Root of the Chart document content, “office:chart”.

Source code in odfdo/body.py
131
132
133
134
135
class Chart(UserFieldDeclContMixin, VarDeclMixin, NRMixin, Body):
    """Root of the Chart document content, "office:chart"."""

    _tag: str = "office:chart"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:chart'

Database

Bases: Body

Root of the Database document content, “office:database”.

Source code in odfdo/body.py
138
139
140
141
142
class Database(Body):
    """Root of the Database document content, "office:database"."""

    _tag: str = "office:database"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:database'

Drawing

Bases: UserFieldDeclContMixin, VarDeclMixin, NRMixin, Body

Root of the Drawing document content, “office:drawing”.

Source code in odfdo/body.py
145
146
147
148
149
class Drawing(UserFieldDeclContMixin, VarDeclMixin, NRMixin, Body):
    """Root of the Drawing document content, "office:drawing"."""

    _tag: str = "office:drawing"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:drawing'

Image

Bases: Body

Root of the Image document content, “office:image”.

Source code in odfdo/body.py
152
153
154
155
156
class Image(Body):
    """Root of the Image document content, "office:image"."""

    _tag: str = "office:image"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:image'

Metadata

Bases: Body

Root of the Meta document content, “office:meta”.

Source code in odfdo/body.py
207
208
209
210
211
class Metadata(Body):
    """Root of the Meta document content, "office:meta"."""

    _tag: str = "office:meta"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:meta'

OfficeSettings

Bases: Body

Root of the Settings document content, “office:settings”.

Methods:

Name Description
as_dict

Serialize the OfficeSettings element and its children to a dictionary.

from_dict

Create an OfficeSettings element from a dictionary representation.

Source code in odfdo/body.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
class OfficeSettings(Body):
    """Root of the Settings document content, "office:settings"."""

    _tag: str = "office:settings"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

    def as_dict(self) -> dict[str, str | int | bool | dict[str, Any] | list[Any]]:
        """Serialize the OfficeSettings element and its children to a dictionary.

        This method recursively converts the element and its child elements
        (if they also have an `as_dict` method) into a dictionary
        representation.

        Returns:
            dict: A dictionary representing the OfficeSettings element,
                where the key is the element's tag and the value is a
                dictionary containing its children's representations.
        """
        conf: dict[str, str | int | bool | dict[str, Any] | list[Any]] = {
            "class": self._tag
        }
        children = [child.as_dict() for child in self.children]  # type: ignore[attr-defined]
        if children:
            conf["children"] = children
        return conf

    @classmethod
    def from_dict(
        cls, data: dict[str, str | int | bool | dict[str, Any]]
    ) -> OfficeSettings:
        """Create an OfficeSettings element from a dictionary representation.

        This class method reconstructs an OfficeSettings element and its
        children from a dictionary previously generated by a method like
        `as_dict()`. It leverages an internal helper `_from_dict` for the
        actual conversion.

        Args:
            data: A dictionary containing the representation of the
                OfficeSettings element, including its tag and children.

        Returns:
            An OfficeSettings instance populated with data from the dictionary.
        """
        return cast(OfficeSettings, _from_dict(data))

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:settings'

as_dict

as_dict() -> dict[
    str, str | int | bool | dict[str, Any] | list[Any]
]

Serialize the OfficeSettings element and its children to a dictionary.

This method recursively converts the element and its child elements (if they also have an as_dict method) into a dictionary representation.

Returns:

Name Type Description
dict dict[str, str | int | bool | dict[str, Any] | list[Any]]

A dictionary representing the OfficeSettings element, where the key is the element’s tag and the value is a dictionary containing its children’s representations.

Source code in odfdo/body.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def as_dict(self) -> dict[str, str | int | bool | dict[str, Any] | list[Any]]:
    """Serialize the OfficeSettings element and its children to a dictionary.

    This method recursively converts the element and its child elements
    (if they also have an `as_dict` method) into a dictionary
    representation.

    Returns:
        dict: A dictionary representing the OfficeSettings element,
            where the key is the element's tag and the value is a
            dictionary containing its children's representations.
    """
    conf: dict[str, str | int | bool | dict[str, Any] | list[Any]] = {
        "class": self._tag
    }
    children = [child.as_dict() for child in self.children]  # type: ignore[attr-defined]
    if children:
        conf["children"] = children
    return conf

from_dict classmethod

from_dict(
    data: dict[str, str | int | bool | dict[str, Any]],
) -> OfficeSettings

Create an OfficeSettings element from a dictionary representation.

This class method reconstructs an OfficeSettings element and its children from a dictionary previously generated by a method like as_dict(). It leverages an internal helper _from_dict for the actual conversion.

Parameters:

Name Type Description Default
data dict[str, str | int | bool | dict[str, Any]]

A dictionary containing the representation of the OfficeSettings element, including its tag and children.

required

Returns:

Type Description
OfficeSettings

An OfficeSettings instance populated with data from the dictionary.

Source code in odfdo/body.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@classmethod
def from_dict(
    cls, data: dict[str, str | int | bool | dict[str, Any]]
) -> OfficeSettings:
    """Create an OfficeSettings element from a dictionary representation.

    This class method reconstructs an OfficeSettings element and its
    children from a dictionary previously generated by a method like
    `as_dict()`. It leverages an internal helper `_from_dict` for the
    actual conversion.

    Args:
        data: A dictionary containing the representation of the
            OfficeSettings element, including its tag and children.

    Returns:
        An OfficeSettings instance populated with data from the dictionary.
    """
    return cast(OfficeSettings, _from_dict(data))

Presentation

Bases: UserDefinedMixin, UserFieldDeclContMixin, LinkMixin, VarDeclMixin, NRMixin, Body

Root of the Presentation document content, “office:presentation”.

Source code in odfdo/body.py
159
160
161
162
163
164
165
class Presentation(
    UserDefinedMixin, UserFieldDeclContMixin, LinkMixin, VarDeclMixin, NRMixin, Body
):
    """Root of the Presentation document content, "office:presentation"."""

    _tag: str = "office:presentation"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:presentation'

Spreadsheet

Bases: UserDefinedMixin, UserFieldDeclContMixin, VarDeclMixin, LinkMixin, AnnotationMixin, NRMixin, Body

Root of the Spreadsheet document content, “office:spreadsheet”.

Source code in odfdo/body.py
168
169
170
171
172
173
174
175
176
177
178
179
180
class Spreadsheet(
    UserDefinedMixin,
    UserFieldDeclContMixin,
    VarDeclMixin,
    LinkMixin,
    AnnotationMixin,
    NRMixin,
    Body,
):
    """Root of the Spreadsheet document content, "office:spreadsheet"."""

    _tag: str = "office:spreadsheet"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:spreadsheet'

Text

Bases: ListMixin, TocMixin, UserDefinedMixin, UserFieldDeclContMixin, LinkMixin, VarDeclMixin, NRMixin, FormMixin, TrackedChangesMixin, OfficeFormsMixin, SectionMixin, ReferenceMixin, BookmarkMixin, AnnotationMixin, NoteMixin, Body

Root of the Text document content, “office:text”.

Source code in odfdo/body.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
class Text(
    ListMixin,
    TocMixin,
    UserDefinedMixin,
    UserFieldDeclContMixin,
    LinkMixin,
    VarDeclMixin,
    NRMixin,
    FormMixin,
    TrackedChangesMixin,
    OfficeFormsMixin,
    SectionMixin,
    ReferenceMixin,
    BookmarkMixin,
    AnnotationMixin,
    NoteMixin,
    Body,
):
    """Root of the Text document content, "office:text"."""

    _tag: str = "office:text"
    _properties: tuple[PropDef | PropDefBool, ...] = ()

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = ()

_tag class-attribute instance-attribute

_tag: str = 'office:text'