473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extract text from ods TableCell using odfpy

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.opendocumen t import Spreadsheet
from odf.opendocumen t import load
from odf.table import TableRow,TableC ell
from odf import text
doc = load("/tmp/match_data.ods" )
d = doc.spreadsheet
rows = d.getElementsBy Type(TableRow)
for row in rows:
cells = row.getElements ByType(TableCel l)
for cell in cells:
print dir(cell.getEle mentsByType(tex t.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.getElements ByType(TableCel l)

users.append((c ells[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.
Aug 25 '08 #1
4 9757
Ok. Sorted it out, but only after taking a round trip over
xml.minidom. Here's the working code:

#!/usr/bin/python
from odf.opendocumen t import Spreadsheet
from odf.opendocumen t import load
from odf.table import TableRow,TableC ell
from odf.text import P
doc = load("/tmp/match_data.ods" )
d = doc.spreadsheet
rows = d.getElementsBy Type(TableRow)
for row in rows[:2]:
cells = row.getElements ByType(TableCel l)
for cell in cells:
tps = cell.getElement sByType(P)
if len(tps) 0:
for x in tps:
print x.firstChild
Aug 26 '08 #2
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.opendocumen t import Spreadsheet
from odf.opendocumen t import load
from odf.table import TableRow,TableC ell
from odf.text import P
doc = load("/tmp/match_data.ods" )
d = doc.spreadsheet
rows = d.getElementsBy Type(TableRow)
for row in rows[:2]:
cells = row.getElements ByType(TableCel l)
for cell in cells:
tps = cell.getElement sByType(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
no******@hughes .net
Aug 26 '08 #3
On Aug 27, 3:04 am, norseman <norse...@hughe s.netwrote:
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.opendocumen t import Spreadsheet
from odf.opendocumen t import load
from odf.table import TableRow,TableC ell
from odf.text import P
doc = load("/tmp/match_data.ods" )
d = doc.spreadsheet
rows = d.getElementsBy Type(TableRow)
for row in rows[:2]:
cells = row.getElements ByType(TableCel l)
for cell in cells:
tps = cell.getElement sByType(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? :)
Consider using:
find --http --google "odfpy"
;-)

Aug 26 '08 #4
Ciaran Farrell wrote:
2008/8/26 norseman <no******@hughe s.net>:
>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.opendocumen t import Spreadsheet
from odf.opendocumen t import load
from odf.table import TableRow,TableC ell
from odf.text import P
doc = load("/tmp/match_data.ods" )
d = doc.spreadsheet
rows = d.getElementsBy Type(TableRow)
for row in rows[:2]:
cells = row.getElements ByType(TableCel l)
for cell in cells:
tps = cell.getElement sByType(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? :)

Sorry. Stupid of me. The module is not part of the standard libary.
It's at http://opendocumentfellowship.com/projects/odfpy

Ciaran
==============
I got the download and all went pretty well. Setup.py compiled OK and
install put it where it belongs.

As a test I went to try odflint and keep getting a zlib not found error.
It is installed (/usr/local/lib) and the python zlib things .py, .pyc
and .pyo all seem present. Not sure what is happening.
I took a look at Python.2.5.2's zipfile.py

statement: import zlib was changed to import libz as zlib
(ALL libs are prefixed with lib... by convention)
Problem below the test happens with or without my change.

Test I ran:

python
(sign on yah de yah yah)
import zipfile
zipfile.is_zipf ile("zx")
False
zipfile.is_zipf ile("zz.zip")
True
zipfile.is_zipf ile("zx.zip")
False (file non existent - no error generated, but answer correct)

Thus all returned correct answers. Distro Python code runs as expected.

However:

odflint OOstuf2.odt |\__
python /usr/local/bin/odflint OOstuf2.odt |/ Both return following:

Traceback (most recent call last):
File "/usr/local/bin/odflint", line 213, in <module>
lint(sys.argv[1])
File "/usr/local/bin/odflint", line 197, in lint
content = zfd.read(zi.fil ename)
File "/usr/local/lib/python2.5/zipfile.py", line 498, in read
"De-compression requires the (missing) zlib module"
RuntimeError: De-compression requires the (missing) zlib module

Anybody:
What did I miss correcting? Seems odflint only uses zipfile.referen ces.

System: Slackware 10.2 on 2.4GgHz Laptop
Steve
no******@hughes .net
Aug 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
308
by: Craig HB | last post by:
I am using an asp.net table to display postings in a classifieds website. This is a section of the HTM I am using... <asp:table id="tblAdvert" Width="466px" Height="78px" runat="server" BackColor="Gainsboro" BorderStyle="Solid" BorderWidth="1px" BorderColor="MidnightBlue" GridLines="Both" CellSpacing="0"> <asp:TableRow> <asp:TableCell></asp:TableCell> </asp:TableRow>
3
16205
by: harry | last post by:
I want to be able to change the text alignment within a table cell between "right" & "center" depending on how many rows are in the table. Is this possible in Javascript? - can't see how to do it! thanks harry
1
2762
by: Bob Voss | last post by:
If I add a hidden input control to a tablecell and then set the cell's text property, the hidden control is not output. If I set the text first, then the hidden control is output but the text is not. No errors are generated. I can make it work by adding a literal control instead of using the text property, but why doesn't the "simple" method work? Dim tCell As TableCell = New TableCell Dim thidden As HtmlInputHidden = New...
2
1264
by: Craig HB | last post by:
I am using an asp.net table to display postings in a classifieds website. This is a section of the HTM I am using... <asp:table id="tblAdvert" Width="466px" Height="78px" runat="server" BackColor="Gainsboro" BorderStyle="Solid" BorderWidth="1px" BorderColor="MidnightBlue" GridLines="Both" CellSpacing="0"> <asp:TableRow> <asp:TableCell></asp:TableCell> </asp:TableRow>
1
2341
by: Krish | last post by:
Hi, I am using table control to create table/cell & 2 text box & one image button during runtime. Onclick event of image button i would like to validate if there is any value in either of text boxes, but my intellisense will not recognize those textboxes created during runtime. How to overcome this issue. Pl. help. protected void Page_Load(object sender, EventArgs e)
16
5190
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString Page.FindControl("tdInput").Controls.Add(txtTest) This successfully creates a textbox called "txtLeft1" in the table
2
1536
by: JonWB | last post by:
Hi, I am very new to .Net and have recently taken over someone else’s project. I am developing an asp webpage using C#. I have an asp:table that is populated using data from a database. However, there is also a column that contains checkboxes and a column that contains text boxes like so: Location | Stock | Issue (checkbox column) | Issued (textbox column) I want the user to click a checkbox and the value of the ‘Stock’ column...
1
4915
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
1
2105
by: yogarajan | last post by:
Hi Friend this is my code protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { TableRow tr = new TableRow();
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.