Creating an open .odt document using Python

How can I create an open office .odt file from Python?

I look at this http://wiki.openoffice.org/wiki/Python , but I'm confused. I already have Python 2.7, so where do I go from here? The link above talks about shipping Open Office with Python. I already got it ?? And do I really need OpenOffice? Isn’t there any kind of template, somehow the document should look so that it is recognized as odt? Do I need a real editor?

I would like something like https://github.com/mikemaccana/python-docx , but for Open Office.

Sorry for this open-ended question, but I really looked around and feel that I am missing some important link / understanding of what is required.

+6
source share
3 answers

I use relatorio to be able to produce ODT. You can see the document here

+13
source

UNO Python bindings allows you to run python scripts inside OpenOffice / LibreOffice, such as Basic macroses.

They allow you to do almost everything that OpenOffice can do on its own, including creating ODT documents, but they must run in a specific environment and depend on OpenOffice.

Here is the basic tutorial for Python-UNO in OpenOffice: http://www.openoffice.org/udk/python/python-bridge.html

To edit ODT documents from Python, I found this library: https://joinup.ec.europa.eu/software/odfpy/home , but I never really tried it.

For my task (a small modification of an existing document), I finished manually editing the XML files in the .odt zod file, using the Python zipfile module and the lxml library to parse and edit the XML.

+2
source

Another possibility is the odfpy module, you can see a short introduction here .

Python APIs and OpenDocument File Tools

Odfpy is a library for reading and writing OpenDocument v files. 1.2. The main attention was paid to ensure that the programmer did not create invalid documents. It has checks that throw an exception if the programmer adds an invalid element, adds an attribute unknown to the grammar, forgets to add the required attribute, or add text to an element that does not allow this.

This is on pipy, so you can install it with

 pip install odfpy 
+2
source

Source: https://habr.com/ru/post/1498915/


All Articles