extract text from ods TableCell using odfpy

norseman norseman at hughes.net
Tue Aug 26 13:04:43 EDT 2008


frankentux wrote:
> Ok. Sorted it out, but only after taking a round trip over
> xml.minidom. Here's the working code:
> 
> #!/usr/bin/python
> from odf.opendocument import Spreadsheet
> from odf.opendocument import load
> from odf.table import TableRow,TableCell
> from odf.text import P
> doc = load("/tmp/match_data.ods")
> d = doc.spreadsheet
> rows = d.getElementsByType(TableRow)
> for row in rows[:2]:
>     cells = row.getElementsByType(TableCell)
>     for cell in cells:
>         tps = cell.getElementsByType(P)
>         if len(tps) > 0:
>             for x in tps:
>                 print x.firstChild
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
=========================
cd /opt
find . -name "*odf*" -print
(empty)
cd /usr/local/lib/python2.5
find . -name "*odf*" -print
(empty)


OK - where is it? :)


Steve
norseman at hughes.net



More information about the Python-list mailing list