Jakarta's POI project provides a set of Java APIs that manipulate the Windows document, which provides the following easy ways for operating Excel files: HSSFWorkbook, HSSFSHEET, HSSFROW, HSSFCell, representings in the Excel spreadsheet, SHEET, line And cells. You can download to the latest POI kit: http://jakarta.apache.org/poi/index.html The following code creates an Excel file Test.xls, and writes in the first line of the first line In one message: import org.apache.poi.hssf.usermodel. *; Import java.io.fileoutputstream; // code run against the jakarta-poi-1.5.0-final-20020506.jar. Public class poitest {static public copublic void main (String [] args) throws Exception {FileOutputStream fos = new FileOutputStream ( "d: /test.xls"); HSSFWorkbook wb = new HSSFWorkbook (); HSSFSheet s = wb.createSheet (); wb.setSheetName (0, "first sheet"; hssfrow rot = s.createrow (0); hssfcell cell = row.createcell (0); cell.setcellValue ("Hello! This Message is generated from poi."); wb.write (fos); Fos.close ();}} When reading an Excel file, you first survive a poifsFileSystem object, constructed a HSSFWorkbook by the PoifsFileSystem object, which represents an Excel document. The following code read the message string written by the Excel file generated above:
POIFSFileSystem fs = null; HSSFWorkbook wb = null; try {fs = new POIFSFileSystem (new FileInputStream ( "d: /test.xls")); wb = new HSSFWorkbook (fs);} catch (IOException e) {e.printStackTrace ( } Hssfsheet sheet = wb.getsheetat (0); hssfrow rot = sheet.Gtrow (0); hssfcell cell = row.getcell (short) 0); string msg = cell.getstringcellValue ();