Bases: object
Representation of an XML element. Abstraction of the XML library behind.
Insert element or text in the last position.
Append the named range to the spreadsheet, replacing existing named range of same name if any.
Arguments:
named_range – ODF named nange
Remove text, children and attributes from the element.
Delete the given element from the XML tree. If no element is given, “self” is deleted. The XML library may allow to continue to use an element now “orphan” as long as you have a reference to it.
if keep_tail is True (default), the tail text is not erased.
Arguments:
child – odf_element
keep_tail – boolean (default to True), True for most usages.
Delete the Named Range of specified name from the spreadsheet.
Arguments:
name – str
Fast append elements at the end of ourself using extend.
Return the annotation that matches the criteria.
Arguments:
position – int
creator – unicode
start_date – date object
end_date – date object
content – unicode regex
name – unicode
Return: odf_annotation or None if not found
Return the annotation end that matches the criteria.
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return all the annotation ends.
Return: list of odf_element
Return all the annotations that match the criteria.
Arguments:
creator – unicode
start_date – date object
end_date – date object
content – unicode regex
Return: list of odf_annotation
Returns elements between tag1 and tag2, tag1 and tag2 shall be unique and having an id attribute. (WARN: buggy if tag1/tag2 defines a malformed odf xml.) If as_text is True: returns the text content. If clean is True: suppress unwanted tags (deletions marks, ...) If no_header is True: existing text:h are changed in text:p By default: returns a list of odf_element, cleaned and without headers.
Implementation and standard retrictions: Only text:h and text:p sould be ‘cut’ by an insert tag, so inner parts of insert tags are:
- any text:h, text:p or sub tag of these
- some text, part of a parent text:h or text:p
Arguments:
tag1 – odf_element
tag2 – odf_element
as_text – boolean
clean – boolean
no_header – boolean
Return: list of odf_paragraph or odf_header
Return the bookmark that matches the criteria.
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return the bookmark end that matches the criteria.
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return all the bookmark ends.
Return: list of odf_element
Return the bookmark start that matches the criteria.
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return all the bookmark starts.
Return: list of odf_element
Return all the bookmarks.
Return: list of odf_element
Return a list of ids that refers to a change region in the tracked changes list.
Get dc:creator value.
Return: unicode (or None if inexistant)
Get the dc:date value.
Return: datetime (or None if inexistant)
Return the document body : ‘office:body’
Return the draw connector that matches the criteria.
Arguments:
position – int
id – unicode
content – unicode regex
Return: odf_shape or None if not found
Return all the draw connectors that match the criteria.
Arguments:
draw_style – unicode
draw_text_style – unicode
content – unicode regex
Return: list of odf_shape
Return the draw ellipse that matches the criteria.
Arguments:
position – int
id – unicode
content – unicode regex
Return: odf_shape or None if not found
Return all the draw ellipses that match the criteria.
Arguments:
draw_style – unicode
draw_text_style – unicode
content – unicode regex
Return: list of odf_shape
Return the draw line that matches the criteria.
Arguments:
position – int
id – unicode
content – unicode regex
Return: odf_shape or None if not found
Return all the draw lines that match the criteria.
Arguments:
draw_style – unicode
draw_text_style – unicode
content – unicode regex
Return: list of odf_shape
Return the draw page that matches the criteria.
Arguments:
position – int
name – unicode
content – unicode regex
Return: odf_draw_page or None if not found
Return all the draw pages that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_draw_page
Return the draw rectangle that matches the criteria.
Arguments:
position – int
id – unicode
content – unicode regex
Return: odf_shape or None if not found
Return all the draw rectangles that match the criteria.
Arguments:
draw_style – unicode
draw_text_style – unicode
content – unicode regex
Return: list of odf_shape
This function must return a beautiful version of the text
Return the section that matches the criteria.
Arguments:
position – int
title – unicode regex
description – unicode regex
content – unicode regex
Return: odf_frame or None if not found
Return all the frames that match the criteria.
Arguments:
style – unicode
title – unicode regex
description – unicode regex
content – unicode regex
Return: list of odf_frame
Return the heading that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_heading or None if not found
Return all the headings that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_heading
Return the image that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_element or None if not found
Return all the sections that match the criteria.
Arguments:
style – str
url – unicode regex
content – unicode regex
Return: list of odf_element
Return the link that matches the criteria.
Arguments:
position – int
name – unicode
title – unicode
url – unicode regex
content – unicode regex
Return: odf_element or None if not found
Return all the links that match the criteria.
Arguments:
name – unicode
title – unicode
url – unicode regex
content – unicode regex
Return: list of odf_element
Return the list that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_list or None if not found
Return all the lists that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_list
Return the named range of specified name, or None if not found.
Arguments:
name – str
Return: odf_named_range
Return all the tables named ranges.
Return: list of odf_named_range
Return the note that matches the criteria.
Arguments:
position – int
note_id – unicode
note_class – ‘footnote’ or ‘endnote’
content – unicode regex
Return: odf_note or None if not found
Return all the notes that match the criteria.
Arguments:
note_class – ‘footnote’ or ‘endnote’
content – unicode regex
Return: list of odf_note
Return all the used office:name tags values of the element.
Return: list of unique str
Return a list of connectors which don’t have any shape connected to them.
Return the paragraph that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_paragraph or None if not found
Return all the paragraphs that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_paragraph
Return the reference mark that match the criteria. Either single position reference mark (text:reference-mark) or start of range reference (text:reference-mark-start).
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return the reference mark end that matches the criteria. Search only the tags text:reference-mark-end. Consider using : get_reference_marks()
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return all the reference mark ends. Search only the tags text:reference-mark-end. Consider using : get_reference_marks()
Return: list of odf_element
Return the reference mark that matches the criteria. Search only the tags text:reference-mark. Consider using : get_reference_mark()
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return the reference mark start that matches the criteria. Search only the tags text:reference-mark-start. Consider using : get_reference_mark()
Arguments:
position – int
name – unicode
Return: odf_element or None if not found
Return all the reference mark starts. Search only the tags text:reference-mark-start. Consider using : get_reference_marks()
Return: list of odf_element
Return all the reference marks, either single position reference (text:reference-mark) or start of range reference (text:reference-mark-start).
Return: list of odf_element
Return all the reference marks. Search only the tags text:reference-mark. Consider using : get_reference_marks()
Return: list of odf_element
Return all the references (text:reference-ref). If name is provided, returns the references of that name.
Return: list of odf_element
Arguments:
name – unicode or None
Return the section that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_element or None if not found
Return all the sections that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_element
Return the span that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_span or None if not found
Return all the spans that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_span
Return the style uniquely identified by the family/name pair. If the argument is already a style object, it will return it.
If the name is not the internal name but the name you gave in the desktop application, use display_name instead.
Arguments:
- family – ‘paragraph’, ‘text’, ‘graphic’, ‘table’, ‘list’,
- ‘number’
name_or_element – unicode or odf_style
display_name – unicode
Return: odf_style or None if not found
Brute-force to find paragraphs, tables, etc. using the given style name (or all by default).
Arguments:
name – unicode
Return: list
Return the table that matches the criteria.
Arguments:
position – int
name – unicode
content – unicode regex
Return: odf_table or None if not found
Return all the tables that match the criteria.
Arguments:
style – unicode
content – unicode regex
Return: list of odf_table
Return the tag name of the element as a qualified name, e.g. “text:span”.
Return: str
Return the text immediately following the element.
Inspired by lxml.
Return the text content of the element.
If recursive is True, all text contents of the subtree.
Return the text change that matches the criteria. Either single deletion (text:change) or start of range of changes (text:change-start). position : index of the element to retrieve if several matches, default is 0. idx : change-id of the element.
Arguments:
position – int
idx – unicode
Return: odf_element or None if not found
Return the text change of deletion kind that matches the criteria. Search only for the tags text:change. Consider using : get_text_change()
Arguments:
position – int
idx – unicode
Return: odf_element or None if not found
Return all the text changes of deletion kind: the tags text:change. Consider using : get_text_changes()
Return: list of odf_element
Return the text change-end that matches the criteria. Search only the tags text:change-end. Consider using : get_text_change()
Arguments:
position – int
idx – unicode
Return: odf_element or None if not found
Return all the text change-end. Search only the tags text:change-end. Consider using : get_text_changes()
Return: list of odf_element
Return the text change-start that matches the criteria. Search only the tags text:change-start. Consider using : get_text_change()
Arguments:
position – int
idx – unicode
Return: odf_element or None if not found
Return all the text change-start. Search only for the tags text:change-start. Consider using : get_text_changes()
Return: list of odf_element
Return all the text changes, either single deletion (text:change) or start of range of changes (text:change-start).
Return: list of odf_element
Like “get_text” but return the text of the embedded paragraph: annotations, cells...
Return the table of contents that matches the criteria.
Arguments:
position – int
content – unicode regex
Return: odf_toc or None if not found
Return all the tables of contents.
Return: list of odf_toc
Return the tracked-changes part in the text body.
return the user defined declaration for the given name.
return: odf_element or none if not found
Return all the user defined field declarations.
Return: list of odf_element
Return the value of the given user defined field name.
Arguments:
name – unicode
- value_type – ‘boolean’, ‘date’, ‘float’,
- ‘string’, ‘time’ or automatic
Return: most appropriate Python type
return the user field declaration for the given name.
return: odf_element or none if not found
Return all the user field declarations.
Return: list of odf_element
Return the container for user field declarations. Created if not found.
Return: odf_element
Return the value of the given user field name.
Arguments:
name – unicode
- value_type – ‘boolean’, ‘currency’, ‘date’, ‘float’,
- ‘percentage’, ‘string’, ‘time’ or automatic
Return: most appropriate Python type
return the variable declaration for the given name.
return: odf_element or none if not found
Return all the variable declarations.
Return: list of odf_element
Return the container for variable declarations. Created if not found.
Return: odf_element
Return the variable set for the given name (last one by default).
Arguments:
name – unicode
position – int
Return: odf_element or None if not found
Return the last value of the given variable name.
Arguments:
name – unicode
- value_type – ‘boolean’, ‘currency’, ‘date’, ‘float’,
- ‘percentage’, ‘string’, ‘time’ or automatic
Return: most appropriate Python type
Return all the variable sets that match the criteria.
Arguments:
name – unicode
Return: list of odf_element
Return the position of the child in this element.
Inspired by lxml
Insert an element relatively to ourself.
Insert either using DOM vocabulary or by numeric position. If text start is True, insert the element before any existing text.
Position start at 0.
Arguments:
element – odf_element
- xmlposition – FIRST_CHILD, LAST_CHILD, NEXT_SIBLING
- or PREV_SIBLING
start – Boolean
position – int
Check if the element is empty : no text, no children, no tail
Return: Boolean
return True if the pattern is found one or more times anywhere in the text content of the element.
Python regular expression syntax applies.
Arguments:
pattern – unicode
Return: bool
Replace the pattern with the given text, or delete if text is an empty string, and return the number of replacements. By default, only return the number of occurences that would be replaced.
It cannot replace patterns found across several element, like a word split into two consecutive spans.
Python regular expression syntax applies.
Arguments:
pattern – unicode
new – unicode
Return: int
Change in place the full document body content.
Replaces in place a sub element with the element passed as second argument.
Warning : no clone for old element.
Return the first position of the pattern in the text content of the element, or None if not found.
Python regular expression syntax applies.
Arguments:
pattern – unicode
Return: int or None
Set dc:creator value.
Arguments:
creator – unicode
Set the dc:date value.
Arguments:
darz – DateTime
Shortcut to accept a style object as a value.
Change the tag name of the element with the given qualified name. Return a new element as there may be a more appropriate class afterwards. XXX side effects?
Arguments:
qname – str
Return: odf_element or a subclass
Set the text immediately following the element.
Inspired by lxml.
Set the text content of the element.
Like “set_text” but set the text of the embedded paragraph: annotations, cells...
Create the paragraph if missing.
Remove the tags of provided elements, keeping inner childs and text.
Return : the striped element.
Warning : no clone in sub_elements list.
Arguments:
sub_elements – odf_element or list of odf_element
Remove the tags listed in strip, recursively, keeping inner childs and text. Tags listed in protect stop the removal one level depth. If the first level element is stripped, default is used to embed the content in the default element. If default is None and first level is striped, a list of text and children is returned. Return : the striped element.
strip_tags should be used by on purpose methods (strip_span ...) (Method name taken from lxml).
Arguments:
strip – iterable list of unicode odf tags, or None
protect – iterable list of unicode odf tags, or None
default – unicode odf tag, or None
Return:
odf_element or list.
Apply XPath query to the element and its subtree. Return list of odf_element or odf_text instances translated from the nodes found.
Bases: unicode
Representation of an XML text node. Created to hide the specifics of lxml in searching text nodes using XPath.
Constructed like any unicode object but only accepts lxml text objects.
Associate a qualified element name to a Python class that handles this type of element.
Getting the right Python class when loading an existing ODF document is then transparent. Unassociated elements will be handled by the base odf_element class.
Most styles use the “style:style” qualified name and only differ by their “style:family” attribute. So the “family” attribute was added to register specialized style classes.
Arguments:
qname – str
cls – Python class
family – str