POI Tutorial First: Create a new workbook, Sheet page, create a cell

Source: Internet
Author: User

First Lecture

About Poi

Apache POI is an open source library of the Apache Software Foundation, where POI provides APIs to Java programs to read and write to Microsoft Office format archives.

1. Create a new workbook and name the workbook

Workbook wb=new//  define a newer workbook fileoutputstream fileout= new FileOutputStream ("c:\\-out workbook with Poi"); Wb.write (fileout); Fileout.close () ;

2. Create a new Sheet page and name the Sheet page

Workbook wb=new//  define a workbook wb.createsheet ("first sheet page");  // Create a first sheet page Wb.createsheet ("second sheet page");  // Create a second sheet page fileoutputstream fileout=new fileoutputstream ("c:\\ with poi out of sheet page. xls"); Wb.write ( Fileout); Fileout.close ();

The effect is as follows:

3. Create a cell and assign a value to the cell
Workbook WB=NewHssfworkbook ();//to define a new workbookSheet Sheet=wb.createsheet ("first sheet page");//Create a first sheet pageRow Row=sheet.createrow (0);//Create a rowcell Cell=row.createcell (0);//Create a cell 1th columnCell.setcellvalue (1);//set a value for a cellRow.createcell (1). Setcellvalue (1.2);//Create a cell the 2nd column value is 1.2Row.createcell (2). Setcellvalue ("This is a string type");//Create a cell with the 3rd column value as a stringRow.createcell (3). Setcellvalue (false);//Create a cell the 4th column value is a Boolean typeFileOutputStream fileout=NewFileOutputStream ("c:\\ Cell.xls with Poi");       Wb.write (fileout); Fileout.close ();

The effect is as follows:

The source code is as follows: HTTP://YUNPAN.CN/CDRTNABGZRGDM access password 4188

POI Tutorial First: Create a new workbook, Sheet page, create a cell

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.