Bases: object
Abstraction of the ODF document.
Insert a file from a path or a fike-like object in the container. Return the full path to reference it in the content.
Arguments:
path_or_file – str or file-like
Return: str
Return an exact copy of the document.
Return: odf_document
Mark a part for deletion. The path is relative to the archive, e.g. “Pictures/100000000000032000000258912EB1C3.jpg”
Remove all style information from content and all styles.
Return: number of deleted styles
Return the body element of the content part, where actual content is inserted.
Return the bytes of the given part. The path is relative to the archive, e.g. “Pictures/100000000000032000000258912EB1C3.jpg”.
“content”, “meta”, “settings”, “styles” and “manifest” are shortcuts to the real path, e.g. content.xml, and return a dedicated object with its own API.
Return available part names with path inside the archive, e.g. [‘content.xml’, ..., ‘Pictures/100000000000032000000258912EB1C3.jpg’]
Return the style uniquely identified by the name/family pair. If the argument is already a style object, it will return it.
If the name is None, the default style is fetched.
If the name is not the internal name but the name you gave in a desktop application, use display_name instead.
Arguments:
- family – ‘paragraph’, ‘text’, ‘graphic’, ‘table’, ‘list’,
- ‘number’, ‘page-layout’, ‘master-page’
name – unicode or odf_element or None
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
Get the ODF type (also called class) of this document.
Insert the given style object in the document, as required by the style family and type.
The style is expected to be a common style with a name. In case it was created with no name, the given can be set on the fly.
If automatic is True, the style will be inserted as an automatic style.
If default is True, the style will be inserted as a default style and would replace any existing default style of the same family. Any name or display name would be ignored.
Automatic and default arguments are mutually exclusive.
All styles can’t be used as default styles. Default styles are allowed for the following families: paragraph, text, section, table, table-column, table-row, table-cell, table-page, chart, drawing-page, graphic, presentation, control and ruby.
Arguments:
style – odf_style
name – unicode
automatic – bool
default – bool
Returns : style name – str
Copy all the styles of a document into ourself.
Styles with the same type and name will be replaced, so only unique styles will be preserved.
Save the document, at the same place it was opened or at the given target path. Target can also be a file-like object. It can be saved as a Zip file (default) or a flat XML file (unimplemented). XML parts can be pretty printed.
Arguments:
target – str or file-like object
packaging – ‘zip’ or ‘flat’, or for debugging purpose ‘folder’
pretty – bool
backup – boolean
Set the bytes of the given part. The path is relative to the archive, e.g. “Pictures/100000000000032000000258912EB1C3.jpg”.
Return an “odf_document” instance of the ODF document stored at the given local path or in the given (open) file-like object.
Examples:
>>> document = odf_get_document('/tmp/document.odt')
>>> stringio = StringIO(...)
>>> document = odf_get_document(stringio)
>>> file = urllib.urlopen('http://example.com/document.odt')
>>> document = odf_get_document(file)
Return an “odf_document” instance using the given template or the template found at the given path.
Examples:
>>> document = odf_new_document(template)
>>> path = 'models/invoice.ott'
>>> document = odf_new_document(path)
if “path” is one of ‘text’, ‘spreadsheet’, ‘presentation’, ‘drawing’ or ‘graphics’, then the lpOD default template is used.
Examples:
>>> document = odf_new_document('text')
>>> document = odf_new_document('spreadsheet')