Python KOffice module(last modified: 10 August, '06)
![]()
A (buried) module that allows you to script KOffice applications with Python.
KOffice is a lovely maturing office suite. It is approximately 4329742 times faster than OpenOffice, integrates with the desktop (nicer file dialogs, KIO), and isn't a 100mb download.
When I looked into it (end of 2004) there was no way to script the applications for automation - something fundamental to office applications I personally think. There was a limited DCOP interface available, but no one wants to use a generic DCOP interface from the command line. I set off to write a module that would let you script KWord, KPresenter, and KSpread in Python, being fairly new to Python at the time and wanting a little challenge. A working yet miniscule module was created and hosted at kde-apps.org.
The project didn't really kick off, however. There was very little interest from the community, both developers and users. A few months later I had a little brainstorming with a developer for Krita, but that died down too.
Usage was trivial - an example which would write text to all empty cells in the range A1:G30 would be as follows:
| 1 | import koffice |
| 2 | kspread = koffice.KSpread() |
| 3 | |
| 4 | i = 1 |
| 5 | for cell in kspread.cellRange("A1", "G30"): |
| 6 | # If the cell has no text in it |
| 7 | if not cell.text(): |
| 8 | # set the text to the value of the variable i |
| 9 | cell.setText(str(i)) |
| 10 | i += 1 |
The module doesn't work with the KOffice version available at the time of writing (1.5). I imagine it's okay with 1.4. I'm only leaving it up to show that I provided a semi-viable, widespread scripting solution for KOffice before the KOffice developers did :P