berhoel.odf package

Give access to ods files.

class berhoel.odf.OdfXml(elem: _Element)[source]

Bases: object

Base XML handling class for ODF processing.

__init__(elem: _Element) None[source]

Intialize instance.

Args: elem (etree._Element): XML Element

find(tag: str) _Element[source]

Find tag in this element.

Parameters:

tag (str) – XML tag to serarch for.

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

findall(tag: str) list[_Element][source]

Find all of tag.

Parameters:

tag (str) – XML tag to find.

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

_attrib_map(attrib: str) str[source]

Helper for get: provide namespace.

Parameters:

attrib (str) – attribute name in the form of <namespace name>:<attr name>.

Returns: str: attribute name with extended namespace.

get(attrib: str) str[source]

Get atribute of this element, honors namespace.

Parameters:

attrib (str) – Attrribute name.

Returns: str: Attribute value.

class berhoel.odf.Odf(path: str | Path)[source]

Bases: OdfXml

Base class for OpenDocument Format files.

__init__(path: str | Path)[source]

Open ODF file from path.

Parameters:

path (str | Path) – Location of OpenOffice file.

Submodules

berhoel.odf.ods module

Processing ods (OpenDocument spreadsheets).

class berhoel.odf.ods.P(elem: _Element)[source]

Bases: OdfXml

Representing a paragraph in a cell.

property text: str | None

Get text from paragraph.

Returns: str: Whole paragraph text if available.

class berhoel.odf.ods.Cell(elem: _Element)[source]

Bases: OdfXml

Representing a cell in a table row.

property text: str | None

Return text associated with cell.

Returns: str: Cell text if avaliable.

property date: date | None

Return date value of cell if available.

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

property value: str | None

Return value of cell.

Returns: str: Value of cell if available.

property float: float | None

Return float value of cell.

Returns: float: float falue of cell if available.

property int: int | None

Return integer value of cell.

Returns: int: int value if cell if available.

property url: str | None

Return URL associated with cell from hyperlink function.

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

Provide Link information.

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

Returns:

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

and line.

Return type:

dict

class berhoel.odf.ods.Row(elem: etree._Element)[source]

Bases: OdfXml

Representing table row.

__init__(elem: etree._Element) None[source]

Initalize instance.

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.

class berhoel.odf.ods.Table(elem: _Element)[source]

Bases: OdfXml

Representation of spreadsheet table.

property name: str

Return name attriute of table.

Returns: str: table name.

property rows: list[Row]

Return rows in table.

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

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.

property hidden: bool

Return whether table is hidden.

Returns: bool: True if table is hidden.

class berhoel.odf.ods.Ods(path: str | Path)[source]

Bases: Odf

Processing ODS files.

__init__(path: str | Path) None[source]

Open ODF spreadsheet file.

property tables: list[Table]

Return all tables in spreadsheet.

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