Skip to content

Reference🔗

berhoel.odf 🔗

Give access to ods files.

Modules:

  • ods –

    Processing ods (OpenDocument spreadsheets).

  • tests –

    Tests for berhoelODF.

Classes:

  • Odf –

    Base class for OpenDocument Format files.

  • OdfXml –

    Base XML handling class for ODF processing.

Classes🔗

berhoel.odf.Odf 🔗

Odf(path: str | Path)

Base class for OpenDocument Format files.

Parameters:

  • path 🔗
    (str | Path) –

    Location of OpenOffice file.

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Source code in src/berhoel/odf/__init__.py
def __init__(self, path: str | Path):
    """Open ODF file from ``path``.

    Args:
       path (str | Path): Location of OpenOffice file.
    """
    with ZipFile(path) as odf_zip, odf_zip.open("content.xml") as content:
        doc = etree.parse(content)
    super().__init__(doc)
Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.OdfXml 🔗

OdfXml(elem: _Element)

Base XML handling class for ODF processing.

Args: elem (etree._Element): XML Element

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Source code in src/berhoel/odf/__init__.py
def __init__(self, elem: etree._Element) -> None:
    """Intialize instance.

    Args:
    elem (etree._Element): XML Element
    """
    self.root = elem
    self.nsmap = (
        self.root.nsmap if hasattr(elem, "nsmap") else self.root.getroot().nsmap
    )
Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.ods 🔗

Processing ods (OpenDocument spreadsheets).

Classes:

  • Cell –

    Representing a cell in a table row.

  • Ods –

    Processing ODS files.

  • P –

    Representing a paragraph in a cell.

  • Row –

    Representing table row.

  • Table –

    Representation of spreadsheet table.

Classes🔗

berhoel.odf.ods.Cell 🔗

Cell(elem: _Element)

Representing a cell in a table row.

Args: elem (etree._Element): XML Element

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Attributes:

  • date (date | None) –

    Return date value of cell if available.

  • float (float | None) –

    Return float value of cell.

  • int (int | None) –

    Return integer value of cell.

  • link (dict[str, str] | None) –

    Provide Link information.

  • text (str | None) –

    Return text associated with cell.

  • url (str | None) –

    Return URL associated with cell from hyperlink function.

  • value (str | None) –

    Return value of cell.

Source code in src/berhoel/odf/__init__.py
def __init__(self, elem: etree._Element) -> None:
    """Intialize instance.

    Args:
    elem (etree._Element): XML Element
    """
    self.root = elem
    self.nsmap = (
        self.root.nsmap if hasattr(elem, "nsmap") else self.root.getroot().nsmap
    )
Attributes🔗
date property 🔗
date: date | None

Return date value of cell if available.

Returns: datetime.date: Date value of cell if available.

float property 🔗
float: float | None

Return float value of cell.

Returns: float: float falue of cell if available.

int property 🔗
int: int | None

Return integer value of cell.

Returns: int: int value if cell if available.

link: dict[str, str] | None

Provide Link information.

This link information is information of values referenced from diffrent tables in formula.

Returns:

  • dict ( dict[str, str] | None ) –

    Result of re.match.groupdict. Provided keys are sheet, row, and line.

text property 🔗
text: str | None

Return text associated with cell.

Returns: str: Cell text if avaliable.

url property 🔗
url: str | None

Return URL associated with cell from hyperlink function.

Returns: str: url from HYPERLINK formula or cell hyperlink.

value property 🔗
value: str | None

Return value of cell.

Returns: str: Value of cell if available.

Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.ods.Ods 🔗

Ods(path: str | Path)

Processing ODS files.

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Attributes:

Source code in src/berhoel/odf/ods.py
def __init__(self, path: str | Path) -> None:
    """Open ODF spreadsheet file."""
    super().__init__(path)

    self.root = self.find("office:body/office:spreadsheet")
Attributes🔗
tables cached property 🔗
tables: list[Table]

Return all tables in spreadsheet.

Returns: List[Table]: Tables in OpenOffice spreadsheet.

Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.ods.P 🔗

P(elem: _Element)

Representing a paragraph in a cell.

Args: elem (etree._Element): XML Element

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Attributes:

  • text (str | None) –

    Get text from paragraph.

Source code in src/berhoel/odf/__init__.py
def __init__(self, elem: etree._Element) -> None:
    """Intialize instance.

    Args:
    elem (etree._Element): XML Element
    """
    self.root = elem
    self.nsmap = (
        self.root.nsmap if hasattr(elem, "nsmap") else self.root.getroot().nsmap
    )
Attributes🔗
text property 🔗
text: str | None

Get text from paragraph.

Returns: str: Whole paragraph text if available.

Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.ods.Row 🔗

Row(elem: _Element)

Representing table row.

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Attributes:

Source code in src/berhoel/odf/ods.py
def __init__(self, elem: etree._Element) -> None:
    """Initalize instance."""
    super().__init__(elem)
    self.content_cell: str = self._attrib_map("table:table-cell")
    self.covered_cell: str = self._attrib_map("table:covered-table-cell")
    self.columns_repeated: str = self._attrib_map("table:number-columns-repeated")
Attributes🔗
cells cached property 🔗
cells: list[Cell | None]

Provide list of cells in row.

Empty cells are replaced by None, as are cells covered by merged cells.

Returns: List[Cell]: The cells making up the current row.

Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))

berhoel.odf.ods.Table 🔗

Table(elem: _Element)

Representation of spreadsheet table.

Args: elem (etree._Element): XML Element

Methods:

  • find –

    Find tag in this element.

  • findall –

    Find all of tag.

  • get –

    Get atribute of this element, honors namespace.

Attributes:

Source code in src/berhoel/odf/__init__.py
def __init__(self, elem: etree._Element) -> None:
    """Intialize instance.

    Args:
    elem (etree._Element): XML Element
    """
    self.root = elem
    self.nsmap = (
        self.root.nsmap if hasattr(elem, "nsmap") else self.root.getroot().nsmap
    )
Attributes🔗
hidden property 🔗
hidden: bool

Return whether table is hidden.

Returns: bool: True if table is hidden.

name cached property 🔗
name: str

Return name attriute of table.

Returns: str: table name.

rows cached property 🔗
rows: list[Row]

Return rows in table.

Returns: List[Row]: list of Row intances.

style_name cached property 🔗
style_name: str

Return table style-name.

I Know of ta1 for ordinary tables, and ta2 for hidden tables.

Returns: str: style name of table.

Functions🔗
find 🔗
find(tag: str) -> _Element

Find tag in this element.

Parameters:

  • tag 🔗 (str) –

    XML tag to serarch for.

Returns: etree._Element: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def find(self, tag: str) -> etree._Element:
    """Find ``tag`` in this element.

    Args:
        tag (str): XML tag to serarch for.

    Returns:
    etree._Element: Element acc. to ``tag``.
    """
    return self.root.find(tag, namespaces=self.nsmap)
findall 🔗
findall(tag: str) -> list[_Element]

Find all of tag.

Parameters:

  • tag 🔗 (str) –

    XML tag to find.

Returns: list[etree._Element]: Element acc. to tag.

Source code in src/berhoel/odf/__init__.py
def findall(self, tag: str) -> list[etree._Element]:
    """Find all of ``tag``.

    Args:
       tag (str): XML tag to find.

    Returns:
    list[etree._Element]: Element acc. to ``tag``.
    """
    return self.root.findall(tag, namespaces=self.nsmap)
get 🔗
get(attrib: str) -> str

Get atribute of this element, honors namespace.

Parameters:

  • attrib 🔗 (str) –

    Attrribute name.

Returns: str: Attribute value.

Source code in src/berhoel/odf/__init__.py
def get(self, attrib: str) -> str:
    """Get atribute of this element, honors namespace.

    Args:
       attrib(str): Attrribute name.

    Returns:
    str: Attribute value.
    """
    return self.root.get(self._attrib_map(attrib))