Fully explore Java Excel API usage

Source: Internet
Author: User
Windows OS users are familiar with Excel (workbooks), but it is not easy to use Java to manipulate Excel files. As Web applications are becoming increasingly popular today, the demand for using Web to operate Excel files is getting stronger and stronger. Currently, a popular operation is to create a CSV (comma separated values) file in JSP or Servlet, the file is returned to the browser as MIME, text/csv, and then the browser calls Excel and displays the CSV file. This is just to say that you can access Excel files, but you cannot really manipulate Excel files. This article will surprise you and introduce you to an open source project, Java Excel API, you can use it to easily manipulate Excel files.
Java Excel API overview
Java Excel is an open source project. Java developers can read the content of an Excel file, create a new Excel file, and update an existing Excel file. Using this API, non-Windows operating systems can also use Java-only applications to process Excel data tables. Because it is written in Java, we can use JSP and Servlet in Web applications to call APIs to access Excel data tables.
The current stable version is V2.0, which provides the following functions:
Reads data from files in Excel formats such as 95, 97, and 2000;
Read the Excel formula (the formulas after Excel 97 can be read );
Generate an Excel data table in the format of Excel 97 );
Supports formatting fonts, numbers, and dates;
Supports cell shadow and color operations;
Modify an existing data table;
The following features are not yet supported, but will be provided soon:
Cannot read chart information;
Can be read, but cannot generate formulas. The final calculated values of any type formulas can be read;

Application example
1. Read data tables from Excel files
Java Excel apican read an Excel data table from a file (.xls) of the internal file system or from an input stream. The first step to read an Excel data table is to create a Workbook (term: work thin). The following code snippet illustrates how to perform this operation: (for the complete code, see ExcelReading. java)
Import java. io .*;
Import jxl .*;
... ... ... ...
Try
{
// Construct a Workbook object, read-only Workbook object
// Create a Workbook directly from a local file
// Create a Workbook from the input stream
InputStream is = new FileInputStream (sourcefile );
Jxl. Workbook rwb = Workbook. getWorkbook (is );
}
Catch (Exception e)
{
E. printStackTrace ();
}
Once a Workbook is created, we can use it to access the Excel Sheet (term: worksheet ). Refer to the following code snippet:
// Obtain the first Sheet
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.