(1) How to use Apache POI to manipulate Excel files-----Getting Started

Source: Internet
Author: User

The goal of the Apache POI project is to use the Java API to create and maintain various Office files (MS Word,ms PowerPoint and Ms Excel). This series of articles is primarily for Excel file operations. For Excel operations, Apache POI offers two models: HSSF and XSSF. The difference, please refer to Figure 1 below. As of May 28, 2015, the current latest version is 3.12. For specific information, we can visit its official website: http://poi.apache.org/


1. Here is the basic code for creating a workbook with Apache POI

Import Org.apache.poi.hssf.usermodel.hssfworkbook;import Java.io.fileoutputstream;import java.io.IOException; public class newworkbooktest{public    static void Main (string[] args)        throws IOException    {        Hssfworkbook wb = new Hssfworkbook ();        FileOutputStream fileout = new FileOutputStream ("Helloworld.xls");        Wb.write (fileout);        Fileout.close ();    }}


2. Here's the code for creating an Excel cell form with Apache POI

Import Org.apache.poi.hssf.usermodel.hssfworkbook;import Org.apache.poi.hssf.usermodel.hssfsheet;import Org.apache.poi.ss.util.workbookutil;import Java.io.ioexception;import Java.io.fileoutputstream;public Class newsheet {public    static void Main (string[] args) throws IOException {        Hssfworkbook wb = new Hssfworkbook ();        Hssfsheet Sheet1 = Wb.createsheet ("Sheet1");        Hssfsheet Sheet2 = Wb.createsheet (); Create with default name        final String name = "Sheet2";        Wb.setsheetname (1, Workbookutil.createsafesheetname (name)); Setting sheet name later        fileoutputstream fileout = new FileOutputStream ("Workbooktest.xls");        Wb.write (fileout);        Fileout.close ();    }}


(1) How to use Apache POI to manipulate Excel files-----Getting Started

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.