Reputation: 13
I have a LibreOffice spreadsheet (data.ods) containing approximately 500 rows of comma separated values in 30 columns. The first row contains the column headers.
Data.ods is updated periodically throughout the day by a script. I then have several links to the cells in data.ods in another spreadsheet (main.ods).
I am currently doing the following:
1) Generate data.ods using a Python script.
2) Open data.ods so that LibreOffice does a Text Import of the comma separated values to populate the rows.
3) Open main.ods (which automatically updates the links).
I am not able to simply leave main.ods open currently because even after closing data.ods, it appears that LibreOffice still has some sort of lock on the file and does not allow my script to edit data.ods until I close LibreOffice altogether (requiring me to close main.ods).
I would like to to do the following:
1) Have main.ods open.
2) Generate data.ods via script.
3) Import updated values into main.ods using Edit...Links...Update Values.
4) Leave main.ods open.
5) Generate new data.ods via script.
6) Import updated values into main.ods using Edit...Links...Update Values.
7) Repeat as necessary.
Upvotes: 1
Views: 3344
Reputation: 61
As jsbueno mentioned, you can run the Python on a document while it is open (and it doesn't block manual editing of a document) by using the uno module.
Agreed that the documentation is currently rubbish. I'm trying to do something about that at www.documenthacker.com / http://documenthacker.wordpress.com, but focusing on Writer. The programs are however similar and you might find the methods for opening documents, navigating documents etc useful - once you get into programming LibreOffice/OpenOffice with Python it becomes fairly easy to work the next problem out.
On the internet there are generally more examples in Java than in Python, unfortunately it's only half-obvious how to translate between examples (on the to-do list for my documentation). The good news is that the Python way is generally a lot simpler.
Upvotes: 0
Reputation: 110456
As you may be aware there are ways of dealing with Open/Libre Offie through Python scripts. It even ships with a Python interpreter of its own.
The problem is that the documentation on how to do it is terrible - but one of the capabilities is exactly to have an externally running Python script to gain access to a Document open on the interface (like a spreadsheet), and add values to it.
It is slow, but it works fine - since you are talking about just a couple hundred rows, the speed won't matter.
Now, let me try to find the documentation for that and get you a link on where to get started: http://www.openoffice.org/udk/python/python-bridge.html#modes
If you paste the example code in there in the Python interactive prompt (needs to be the Python installed along LibreOffice), you will be able to introspect the available methods and attributes with Python's dir
and find out the method calls to edit cell contents from a script.
Upvotes: 0