ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Jython-users
Jython-users
RE: [Jython-users] jython and excel
by brian zimmer other posts by this author
May 6 2003 1:33AM messages near this date
RE: [Jython-users] jython and excel | [Jython-users] Running embedded Jython from Weblogic 6.1 using an EAR
In addition to using dbexts, you can use this wrapper around jakarta's
POI:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/zxpy/zxPy/src/python/poi.
py?rev=1.5&content-type=text/vnd.viewcvs-markup

It has a more pythonic API around POI's Java-centric library and can be
used to both read and write to an excel workbook.  It does not expose
*everything* from POI but it does expose alot.

---------------------------
import poi
from mx.DateTime import now
w = poi.Workbook()
s = w.createSheet("test")
r = s.createRow()
r.append("Title1")
r.append("Title2")
r = s.createRow()
r.append("A")
r.append(1)
r = s.createRow()
r.append("B")
r.append(now())

for r in s:
 print
 for c in r:
  print c,
 print

fp = open("test.xls", "wb")
w.save(fp)
fp.close()
---------------------------

thanks,

brian


>  -----Original Message-----
>  From: jython-users-admin@[...].net 
>  [mailto:jython-users-admin@[...].net] On Behalf 
>  Of Chris van Mels
>  Sent: Monday, May 05, 2003 12:43 PM
>  To: 'jython-users@lists.sourceforge.net'
>  Subject: RE: [Jython-users] jython and excel
>  
>  
>  Here's a quick example using Jython's "dbexts" package and 
>  connecting via a JDBC-ODBC bridge:
>  
>  1. Create a test excel file:
>  
>  (note: the sheet name corresponds to table name, 
>           and row 1 entries correspond to column names)
>  
>  -------------------------------------------
>  
>  FIRST	LAST	AGE
>  A	Jones	20
>  B	Smith	25
>  
>  -------------------------------------------
>  
>  and save as "excel_test.xls"
>  
>  2. In Windows control panel create ODBC connection of type 
>  "System DSN" using the Microsoft Excel driver - call it 
>  "excel_test" and point to the "excel_test.xsl" file as the 
>  data source.
>  
>  3. Create a text file called "dbexts.ini" containing:
>  
>  -------------------------------------------
>  
>  [default]
>  name=excel_test
>  
>  [jdbc]
>  name=excel_test
>  url=jdbc:odbc:excel_test
>  user=
>  pwd=
>  driver=sun.jdbc.odbc.JdbcOdbcDriver
>  
>  -------------------------------------------
>  
>  4. From same directory as "dbexts.ini" launch Jython 
>  
>  >>> from dbexts import dbexts
>  
>  >>> excel_connection = dbexts("excel_test", "dbexts.ini")
>  
>  >>> query = "select * from [Sheet1$]"
>  
>  >>> excel_connection.isql(query)
>  
>  and you should see the contents of the excel file displayed.
>  
>  (note: the "table" name must be appended with "$" dollar sign 
>  and escaped by wrapping in square brackets)
>  
>  - Chris
>  
>  
>  > ----------
>  > From: 	Updike, Clark[SMTP:Clark.Updike@[...].edu]
>  > Sent: 	Monday, May 05, 2003 12:57 PM
>  > To: 	'jython-users@lists.sourceforge.net'
>  > Subject: 	RE: [Jython-users] jython and excel
>  > 
>  > If you don't need to interact with the excel in real-time, 
>  just write 
>  > out your data in csv format with a .csv extension. Excel 
>  will open the 
>  > file directly.  If you can launch excel from a command prompt, you 
>  > could use os.system to run it supplying the file to open as an arg 
>  > (but finding an excel executable may be harder than you 
>  think).  This
>  > sample writes out file that can be opened directly by 
>  > excel:
>  > 
>  > >>>  f=open('/temp/test.csv','w')
>  > >>>  tab=[['a','1'],['b','2']]
>  > >>>  f.write("\n".join([','.join(row) for row in tab]))
>  > >>>  f.close()
>  > 
>  > If you need to control excel from jython, look at:
>  > 
>  > 
>  http://www.javaworld.com/javaworld/javaqa/2002>
-05/01-qa-0503-excel3.ht
>  > ml
>  > 
>  > -Clark
>  > 
>  > -----Original Message-----
>  > From: Cherney John-CJC030 [mailto:John.Cherney@[...].com]
>  > Sent: Monday, May 05, 2003 12:26 PM
>  > To: jython-users@[...].net
>  > Subject: [Jython-users] jython and excel
>  > 
>  > 
>  > Is there a way to get at information in an Excel 
>  spreadsheet directly 
>  > rather than saving the Excel file as a text file (XML, 
>  HTML, csv) and 
>  > parsing it? Is there a way at the document model along the 
>  same lines 
>  > as what you can do
>  > with VBA?
>  > 
>  > Thanks,
>  > jwc
>  > --- 
>  > John Cherney          | Motorola Inc 
>  > Software Engineer     | phone:(248)994-7713
>  > Network Transport     |   fax:(248)324-9550 
>  > CGISS                 | pager:(888)878-1354 
>  > 
>  > 
>  > -------------------------------------------------------
>  > This sf.net email is sponsored by:ThinkGeek
>  > Welcome to geek heaven.
>  > http://thinkgeek.com/sf 
>  > _______________________________________________
>  > Jython-users mailing list
>  > Jython-users@[...].net
>  > https://lists.sourceforge.net/lists/listinfo/jython-users
>  > 
>  
>  
>  -------------------------------------------------------
>  This sf.net email is sponsored by:ThinkGeek
>  Welcome to geek heaven.
>  http://thinkgeek.com/sf 
>  _______________________________________________
>  Jython-users mailing list
>  Jython-users@[...].net
>  https://lists.sourceforge.net/lists/listinfo/jython-users
>  



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Jython-users mailing list
Jython-users@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-users
Thread:
Chris van Mels
brian zimmer

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved