1. Demand
Reading data from a hello.xls table in Java code
2. Hello.xls form
3. Java code
Packagecom.test; ImportJava.io.File; ImportJxl.*; Public classreadexcel{ Public Static voidMain (string[] args) {inti; Sheet Sheet; Workbook Book; Cell Cell1,cell2,cell3,cell4,cell5,cell6,cell7; Try { //Hello.xls is the Excel file name to readbook= Workbook.getworkbook (NewFile ("D://hello.xls")); //get the first sheet object (sheet's number in Ecxel starts with 0, 0,1,2,3,....) Sheet=book.getsheet (0); //get the cell in the upper-left cornerCell1=sheet.getcell (0,0); System.out.println ("Title:" +cell1.getcontents ()); I=1; while(true) { //get the cells for each rowCell1=sheet.getcell (0,i);//(column, row)Cell2=sheet.getcell (1, i); Cell3=sheet.getcell (2, i); CELL4=sheet.getcell (3, i); CELL5=sheet.getcell (4, i); Cell6=sheet.getcell (5, i); CELL7=sheet.getcell (6, i); if("". Equals (Cell1.getcontents ()) = =true)//if the data being read is empty Break; System.out.println (cell1.getcontents ()+ "\ T" +cell2.getcontents () + "\ T" +cell3.getcontents () + "\ T" +cell4.getcontents ()+ "\ T" +cell5.getcontents () + "\ T" +cell6.getcontents () + "\ T" +cell7.getcontents ()); I++; } book.close (); } Catch(Exception e) {}}}
4. Read the result
Blogs to: 52836770
Java reads data from an Excel table