Class DocIoPartial

class ooodev.utils.partial.doc_io_partial.DocIoPartial(owner, lo_inst=None)[source]
__init__(owner, lo_inst=None)[source]
Parameters:
  • owner (_T) –

  • lo_inst (LoInst | None) –

close(deliver_ownership=True)[source]

Try to close the Document.

Nobody can guarantee real closing of called object - because it can disagree with that if any still running processes can’t be canceled yet. It’s not allowed to block this call till internal operations will be finished here.

Parameters:

deliver_ownership (bool, optional) – If True ownership is delivered to caller. Default True. True delegates the ownership of this closing object to anyone which throw the CloseVetoException. This new owner has to close the closing object again if his still running processes will be finished. False let the ownership at the original one which called the close() method. They must react for possible CloseVetoExceptions such as when document needs saving and try it again at a later time. This can be useful for a generic UI handling.

Raises:

CancelEventError – If Saving event is canceled.

Returns:

True if document was closed; Otherwise, False.

Return type:

bool

See also

See LibreOffice API: XCloseable.close()

classmethod create_doc() ooodev.utils.partial.doc_io_partial._T[source]
classmethod create_doc(*, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(*, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(*, lo_inst: ooodev.loader.inst.lo_inst.LoInst, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(loader: com.sun.star.frame.XComponentLoader, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc(loader=None, lo_inst=None, **kwargs)

Creates a new document.

Parameters:
  • loader (XComponentLoader, optional) – Component Loader. Usually generated with Lo

  • lo_inst (LoInst) – Lo Instance. Use when creating multiple documents. Defaults to None.

  • visible (bool) – If True document is visible; Otherwise, document is invisible. Default False.

  • kwargs (Any) –

Returns:

Class instance representing document.

Return type:

_T

classmethod create_doc_from_template(template_path: Any) ooodev.utils.partial.doc_io_partial._T[source]
classmethod create_doc_from_template(template_path: Any, *, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc_from_template(template_path: Any, loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc_from_template(template_path: Any, loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod create_doc_from_template(template_path, loader=None, lo_inst=None)

Create a document from a template.

Parameters:
  • template_path (PathOrStr) – path to template file.

  • loader (XComponentLoader, optional) – Component Loader.

  • lo_inst (LoInst, optional) – Lo instance. Used when created multiple documents.

Raises:

Exception – If unable to create document.

Returns:

Class instance representing document.

Return type:

_T

classmethod create_macro_doc(*, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T[source]
classmethod create_macro_doc(loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod create_macro_doc(loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod create_macro_doc(loader=None, lo_inst=None)

Create a document that allows executing of macros.

Parameters:
  • loader (XComponentLoader) – Component Loader.

  • lo_inst (LoInst, optional) – Lo Instance. Use when creating multiple documents. Defaults to None.

Returns:

Class instance representing document.

Return type:

_T

Attention

create_doc() method is called along with any of its events.

classmethod from_current_doc()[source]

Get a document from the current component.

This method is useful in macros where the access to current document is needed. This method does not require the use of the MacroLoader in macros.

Parameters:

lo_inst (LoInst, optional) – Lo Instance. Use when creating multiple documents. Defaults to None.

Returns:

Class instance representing document.

Return type:

_T

Example

from ooodev.calc import CalcDoc
doc = CalcDoc.from_current_doc()
doc.sheets[0]["A1"].Value = "Hello World"

See also

ooodev.utils.lo.Lo.current_doc

classmethod get_doc_from_component(doc, lo_inst)[source]

Gets a document.

Parameters:
  • doc (XComponent) – Component to build Draw document from.

  • lo_inst (LoInst | None) –

Raises:

Exception – If not a Draw document.

Returns:

Document.

Return type:

_T

classmethod open_doc(fnm: Any) ooodev.utils.partial.doc_io_partial._T[source]
classmethod open_doc(fnm: Any) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, *, lo_inst: LoInst | None) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, *, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, *, lo_inst: ooodev.loader.inst.lo_inst.LoInst, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_doc(fnm, loader=None, lo_inst=None, **kwargs)

Open a office document.

Parameters:
  • fnm (PathOrStr) – path of document to open.

  • loader (XComponentLoader, optional) – Component Loader.

  • lo_inst (LoInst, optional) – Lo Instance. Use when creating multiple documents. Defaults to None.

  • visible (bool) – If True document is visible; Otherwise, document is invisible. Default False.

  • kwargs (Any) –

Raises:

CancelEventError – if DOC_OPENING event is canceled.

Returns:

Class instance representing document.

Return type:

_T

Events:

Note

Event args event_data is a dictionary containing all method parameters.

See also

Note

If connection it office is a remote server then File URL must be used, such as file:///home/user/fancy.odt

classmethod open_flat_doc(fnm: Any) ooodev.utils.partial.doc_io_partial._T[source]
classmethod open_flat_doc(fnm: Any, *, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod open_flat_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod open_flat_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod open_flat_doc(fnm, loader=None, lo_inst=None)

Opens a flat document.

Parameters:
  • fnm (PathOrStr) – path of XML document.

  • loader (XComponentLoader, optional) – Component loader.

  • lo_inst (LoInst, optional) – Lo instance. Used when created multiple documents.

Raises:

Exception – if unable to open document.

Returns:

Class instance representing document.

Return type:

_T

See also

classmethod open_readonly_doc(fnm: Any) ooodev.utils.partial.doc_io_partial._T[source]
classmethod open_readonly_doc(fnm: Any, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm: Any, *, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, lo_inst: ooodev.loader.inst.lo_inst.LoInst, *, visible: bool) ooodev.utils.partial.doc_io_partial._T
classmethod open_readonly_doc(fnm, loader=None, lo_inst=None, **kwargs)

Open a office document as read-only.

Parameters:
  • fnm (PathOrStr) – path of document to open.

  • loader (XComponentLoader) – Component Loader.

  • lo_inst (LoInst, optional) – Lo instance. Used when created multiple documents.

  • kwargs (Any) –

Returns:

Class instance representing document.

Return type:

_T

save_doc(fnm: Any) bool[source]
save_doc(fnm: Any, password: str) bool
save_doc(fnm: Any, password: str, format: str) bool
save_doc(fnm, password=None, format=None)

Save document.

Parameters:
  • fnm (PathOrStr) – file path to save as.

  • password (str, optional) – password to save document with.

  • format (str, optional) – document format such as ‘odt’ or ‘xml’.

Raises:

CancelEventError – If Saving event is canceled.

Returns:

False if DOC_SAVING event is canceled; Otherwise, True

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing all method parameters.

Attention

store_doc() method is called along with any of its events.

DOC_TYPE: ClassVar[DocType]