|
From: Alfonso R. <ms...@re...> - 2007-10-14 15:02:20
|
This Jython code will open and read an existant Excel file. File Book1.xls = is attached. http://www.nabble.com/file/p13199712/Book1.xls Book1.xls=20 To do:=20 - create the excel file if it doesn't exist=20 - a nicer printing method=20 - a method to print values or formulas in the cells=20 """ read.py Read an existant Excel file (Book1.xls) and show it on the screen """ =20 from org.apache.poi.hssf.usermodel import * from java.io import FileInputStream; file =3D "H:Book1.xls" print file fis =3D FileInputStream(file) wb =3D HSSFWorkbook(fis); sheet =3D wb.getSheetAt(0); # get No. of rows rows =3D sheet.getPhysicalNumberOfRows(); print wb, sheet, rows cols =3D 0; # No. of columns tmp =3D 0; # This trick ensures that we get the data properly even if it # doesn=E2=80=99t start from first few rows for i in range(0, 10,1): row =3D sheet.getRow(i); if(row !=3D None): tmp =3D sheet.getRow(i).getPhysicalNumberOfCells(); if(tmp > cols): cols =3D tmp; print cols for r in range(0, rows, 1): row =3D sheet.getRow(r); print r if(row !=3D None): for c in range(0, cols, 1): cell =3D row.getCell(c); if(cell !=3D None): print cell #wb.close() fis.close(); --=20 View this message in context: http://www.nabble.com/Read-and-Excel-file-wit= h-Apache-POI.-Jython-Examples-tf4622033.html#a13199712 Sent from the jython-users mailing list archive at Nabble.com. |