Java Control Excel Instance

Source: Internet
Author: User
Tags file system

Friends with Windows operating systems are certainly not unfamiliar with Excel (spreadsheets), but it's not easy to manipulate Excel files using the Java language. Today, with the growing popularity of Web applications, the need to manipulate Excel files through the Web is growing, and the more popular operation is to create a CSV (comma separated values) file in a JSP or servlet and mime,text/the file to The CSV type is returned to the browser, then the browser calls Excel and displays the CSV file. This is just to say that you can access the Excel file, but you can't really manipulate the Excel file, this article will give you a surprise, to introduce an open source project Java Excel API, you can easily manipulate Excel files.

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. The stable version now released is V2.0, which provides the following features:

• Read data from files in Excel 95, 97, 2000, and so on;

• Read Excel formulas (you can read the formulas after Excel 97);

• Generate Excel Datasheet (formatted as Excel 97);

• Support the formatting of fonts, numbers and dates;

• Support for cell shadow operation and color operation;

• Modification of existing data tables;

· The following features are not currently supported, but will be available shortly:

• Unable to read chart information;

Can be read, but cannot generate formulas, the final calculation of any type of formula can be read out;

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 how it should be done: (see Excelreading.java for full code)

import java.io.*;
import jxl.*;
… … … …
try
{
//构建Workbook对象, 只读Workbook对象
//直接从本地文件创建Workbook
//从输入流创建Workbook
InputStream is = new FileInputStream(sourcefile);
jxl.Workbook rwb = Workbook.getWorkbook(is);
}
catch (Exception e)
{
e.printStackTrace();
}

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.