Java reads data from an Excel table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.