Use Java to read data in Excel tables.

Source: Internet
Author: User

Introduction to JAVA EXCEL APIs
Java Excel is an open source project through which Java developers can read the contents of Excel files, create new Excel files, and update existing Excel files. Using this API non-Windows operating systems can also work with Excel data tables through a pure Java application. Because it is written in Java, we can use the JSP, servlet to invoke the API to implement the access to Excel datasheet in the Web application.

application Example
Reading data tables from Excel files

The Java Excel API can read Excel data tables from either a file in the local file system (. xls) or from an input stream.   The first step in reading an Excel datasheet is to create a workbook (term: Workbook), and the following code snippet illustrates what to do: you need to use an open source jar package, Jxl.jar. Download Address

File File = new file ("C:\\a.xls");
InputStream in = new FileInputStream (file);
Workbook workbook = Workbook.getworkbook (in);
Get the first sheet of Sheet table
Sheet Sheet = workbook.getsheet (0);

We can access it either through the name of the sheet or through the subscript. If you are accessing by subscript, note that the subscript starts at 0, just like an array.
//Get the first row, the value 
of the first column Cell c00 = Rs.getcell (0, 0); 
String strc00 = c00.getcontents (); 
Gets the first row, the value of the second column 
Cell c10 = Rs.getcell (1, 0); 
String STRC10 = c10.getcontents (); 
We can get the specified cell cell object by specifying the row and column cells
= Sheet.getcell (column, row);
You can also get all cell objects in a row or column
cell[] cells = sheet.getcolumn (column);
cell[] Cells2 = Sheet.getrow (row);
And then take the value of each cell.
String content = cell.getcontents ();

There are many other ways in this jar bag that need to be groped for yourself.

Related Article

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.