Poi initial experience

Source: Internet
Author: User

Apache poi is an open-source library of the Apache Software Foundation. Poi provides APIs for Java programs to read and write Microsoft Office files.

Its structure is as follows:

Hssf-provides the ability to read and write Microsoft Excel files: hssf is the abbreviation of horrible spreadsheet format, that is, "annoying spreadsheet format ". Perhaps the hssf name is a bit funny. In essence, it is a very serious and formal API. With hssf, you can use pure Java code to read, write, and modify Excel files. Xssf-provides the ability to read and write files in Microsoft Excel ooxml format. Hwpf-read and write Microsoft Word files. Hslf-supports reading and writing Microsoft PowerPoint files. Hdgf-read and write Microsoft Visio files. As the key to getting started, this blog briefly introduces how to use poi to generate a simple Excel file, starting with an annoying spreadsheet format. You only need five steps: Of course, you must first introduce the poijar package. This is not one of the steps. (* ^__ ^ *) Hey ...... Log onto the poi website. Create a javaweb project, create a class, and start your poi journey.
1 package COM. myjava. poi; 2 3 Import Java. io. fileoutputstream; 4 5 import Org. apache. poi. hssf. usermodel. hssfworkbook; 6 Import Org. apache. poi. SS. usermodel. cell; 7 Import Org. apache. poi. SS. usermodel. row; 8 Import Org. apache. poi. SS. usermodel. sheet; 9 Import Org. apache. poi. SS. usermodel. workbook; 10 11 public class exceldemo {12 13 public static void main (string [] ARGs) throws exception {14/*** Step 1: Set Define a new workbook 16 */17 workbook WB = new hssfworkbook (); 18/** 19 * Step 2: Create a sheet page 20 */21 sheet = WB. createsheet ("first sheet page"); 22/** 23 * Step 3: Create a row 24 */25 row = sheet in this sheet page. createrow (0); 26/** 27 * Step 4: Create a cell 28 */29 cell = row in this row. createcell (0); 30/** 31 * Step 5: set the value of 32 */33 cell in the cell. setcellvalue (8); 34 35 // 36 rows for cells of different types. createcell (1 ). setcellvalue (8.8); 37 row. createcell (2 ). setcellvalue ("Hello, I am String type "); 38 row. createcell (3 ). setcellvalue (true); 39 // output 40 fileoutputstream fileout = new fileoutputstream ("D: \ poi .xls"); 41 WB. write (fileout); 42 system. out. println ("OK! "); 43 fileout. Close (); 44} 45}

 

In this simple way, the xls file under the corresponding directory has been generated, which is the content we set. In this way, you can easily complete your first poi journey. Welcome to the poi gate. In the project, in addition to importing and exporting Excel or Word documents, the use of poi is also used in the recent project. Download Word Based on the template. Let's learn and apply it, coming soon.

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.