OpenOffice is a free, open source office suite with an API that allows developers to work with it in a number of languages. Python-UNO lets you work with the API in Python. This article gives you a taste of what you can do with it.
Now that we have a blank document with which to work, let's start on our table. We'll make a table of five countries that gives the population for each country. So, we'll have six rows, including a header row, and two columns. Here's how to create a table:
>>> population = document.createInstance ("com.sun.star.text.TextTable")
Of course, we now have to pass the number of rows and columns our table will have. This is done by passing the two values as arguments of the initialize method:
If you're looking at your document, you still won't see the table. Before it is visible, we have to insert it, which is similar to inserting text:
We're now ready to being inserting text into our table. This involves referencing each cell by its name and then setting text. The first row is named "A", and the first column is named "1". This naming pattern continues to the end, and the cells are named by combining the row's name and the column's name. Let's insert our headers:
OpenOffice.org is quite a powerful tool, especially since it contains an API that can be used by several different languages. Fortunately, that list of languages includes Python, something made possible by Python-UNO. Python developers can import the library and create a local context component, which can be used to access OpenOffice.org's context component. Once connected, a developer can begin modifying a document. Although this article only looked at inserting text and tables and changing simple properties, OpenOffice.org's API does not stop there. Text and tables can be modified in many more ways that we looked at here, and we only looked at OpenOffice.org Writer, not any of the other applications included with the OpenOffice.org suite.
There are plenty of places you can go from here. Try creating scripts that generate documents automatically, and take a look through the API if you need access to a feature but can't quite figure out how to go about accessing it: