extract text from ods TableCell using odfpy

frankentux cfarrell1980 at googlemail.com
Mon Aug 25 16:29:16 EDT 2008


Hi there,

I'm losing hair trying to figure out how I can actually get the text
out of an existing .ods file. Currently I have:
#!/usr/bin/python
from odf.opendocument import Spreadsheet
from odf.opendocument import load
from odf.table import TableRow,TableCell
from odf import text
doc = load("/tmp/match_data.ods")
d = doc.spreadsheet
rows = d.getElementsByType(TableRow)
for row in rows:
    cells = row.getElementsByType(TableCell)
    for cell in cells:
        print dir(cell.getElementsByType(text.P))

This is a spreadsheet containing 200 rows, each with 4 cells
containing strings. What I'd like to be able to do is something like:
for row in rows:
    cells = row.getElementsByType(TableCell)
 
users.append((cells[0].value,cells[1].value,cells[2].value,cells[3].value))

Thus, what I'd like to know is how to actually get the value out of
the cell. I've read through the odfpy api documentation (which is
almost completely focused on writing, not reading) and googled for
info, but I still haven't found anything.



More information about the Python-list mailing list