Fedora Linux Support Community & Resources Center
  #1  
Old 26th May 2012, 09:45 PM
idoitprone Offline
Registered User
 
Join Date: May 2012
Location: nowhere
Posts: 13
linuxfirefox
How to configure jython to use apachi poi

I am learning how to program with jython and I need to read excel files, but I am unable to get this package imported; apache-poi.noarch : The Java API for Microsoft Documents

I have all jython and apache-poi installed on my machine. It does not seem to work


I found this example on the web

Code:
#!/usr/bin/jython
""" read.py
Read an existant Excel file (Book1.xls) and show it on the screen
"""
from org.apache.poi.hssf.usermodel import *
from java.io import FileInputStream

file = "Book1.xls"
print file
fis = FileInputStream(file)
wb = HSSFWorkbook(fis)
sheet = wb.getSheetAt(0)

# get No. of rows
rows = sheet.getPhysicalNumberOfRows()
print wb, sheet, rows

cols = 0 # No. of columns
tmp = 0

# This trick ensures that we get the data properly even if it
# doesn't start from first few rows
for i in range(0, 10,1):
  row = sheet.getRow(i)
  if(row != None):
       tmp = sheet.getRow(i).getPhysicalNumberOfCells()
       if tmp > cols:
          cols = tmp
print cols

for r in range(0, rows, 1):
  row = sheet.getRow(r)
  print r
  if(row != None):
    for c in range(0, cols, 1):
        cell = row.getCell(c)
        if cell != None:
            print cell

#wb.close()
fis.close()
I get leep getting this error

Code:
Traceback (innermost last):
  File "./exceltest.py", line 5, in ?
ImportError: no module named poi


http://wiki.python.org/jython/PoiExample

I am using fedora 17
Reply With Quote
  #2  
Old 26th May 2012, 10:34 PM
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 6,121
linuxfirefox
Re: How to configure jython to use apachi poi

The problem is that the apache-poi package you probably installed via yum:
Quote:
yum install apache-poi
is implemented as Java jar files:

rpm -ql apache-poi

will show you those jars are under /usr/share/java/poi

but your jython script is only looking at python library paths for modules. One way to get that "poi.jar" in your script is to replace that "from org.apache.poi.hssf.usermodel import *" line with:

Quote:
import sys
sys.path.append("/usr/share/java/poi/poi.jar")
from org.apache.poi.hssf.usermodel import *
I tried that here and it worked with Pycharm IDE. I suspect there's a better way to include jars in Pycharm but I didn't see it in the "edit configuration" tool.
Then to make sure that even the raw script was working I went to where I put my testpoi.py (copy and paste of your script with my couple lines of edits as shown above)
in my pycharm project:

Quote:
cd ~/PycharmProjects/untitled2/
chmod +x testpoi.py
ls -l
-rw-rw-r--. 1 mos mos 6656 May 26 17:36 Book1.xls
-rwxrwxr-x. 1 mos mos 1005 May 26 17:26 testpoi.py*
(note Book1.xls is a simple two row spreadsheet I made for my test containing two rows with some numbers in them like this:
1 2 3
4 4 5
)

Then I just ran it is a raw command line script so it's not running from Pycharm:
Quote:
./testpoi.py

Picked up _JAVA_OPTIONS: -Dswing.aatext=true -Dawt.useSystemAAFontSettings=on -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKL ookAndFeel
Book1.xls
org.apache.poi.hssf.usermodel.HSSFWorkbook@5be7ef2 c org.apache.poi.hssf.usermodel.HSSFSheet@580760d7 2
3
0
1.0
2.0
3.0
1
4.0
4.0
5.0
So that works too.

PS. another thing to watch for, I was just trying jython support in Fedora 16 and found that because the jython package in Fedora is very
old and behind the current version (Fedora 16 has version 2.2.1 while the latest stable jython is 2.5.2), some things you're accustomed to using
in normal python 2.7 (like the "with open() as file:" context statement (see: http://effbot.org/pyref/with.htm ) won't work.


Mark

Last edited by marko; 27th May 2012 at 05:55 AM.
Reply With Quote
  #3  
Old 27th May 2012, 04:09 PM
idoitprone Offline
Registered User
 
Join Date: May 2012
Location: nowhere
Posts: 13
windows_8firefox
Re: How to configure jython to use apachi poi

thnks. It doesnt really matter which python version to me because I am just using it to call some java apis
Reply With Quote
Reply

Tags
apachi, configure, jython, poi

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help with ./configure x0acake Using Fedora 2 23rd July 2011 08:47 PM
VNC - configure kvfletch Guides & Solutions (No Questions) 15 15th October 2006 02:30 AM
about ./configure AHAROON111 Using Fedora 4 13th April 2006 04:14 PM
how to configer Apachi and PHP in fedora niloshima Using Fedora 2 15th June 2004 02:34 PM


Current GMT-time: 19:55 (Monday, 22-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
...UNION Barrelhouse Travel Photos - Our Lady of Mt. Carmel Photos - Wimpy, the Grove Nelspruit Photos on Instagram