(a) Java uses POI to manipulate excel

Source: Internet
Author: User

1,poi Introduction Apache poi is a free open source cross-platform Java Api,apache poi written in Java that provides APIs for Java programs to read and write to Microsoft Office format Files poi as "Poor Obfuscationmplementation "the initials, meaning" poor fuzzy realization ". Apache POI is a Java API that creates and maintains operations for various office Open XML (OOXML) compliant and Microsoft OLE 2 composite document formats (OLE2). You can use Java to read and create and modify MS Excel files. Also, you can use Java to read and create MS Word and mspowerpoint files. Apache POI provides Java operations for Excel Solutions (for excel97-2008).

Jar Package Download:

Official website: http://poi.apache.org/download.html

Baidu Cloud: http://pan.baidu.com/s/1bpp0C9p

Password: p45i

2. Create a new workbook

Demo1.java

1  PackageCom.wishwzp.poi;2 3 ImportJava.io.FileOutputStream;4 5 ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook;6 ImportOrg.apache.poi.ss.usermodel.Workbook;7 8  Public classDemo1 {9 Ten      Public Static voidMain (string[] args)throwsException { OneWorkbook wb=NewHssfworkbook ();//to define a new workbook AFileOutputStream fileout=NewFileOutputStream ("d:\\ out of the workbook with POI. xls"); - Wb.write (fileout); - fileout.close (); the     } -}

3, create a new sheet page

Demo2.java

1  PackageCom.wishwzp.poi;2 3 ImportJava.io.FileOutputStream;4 5 ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook;6 ImportOrg.apache.poi.ss.usermodel.Workbook;7 8  Public classDemo2 {9 Ten      Public Static voidMain (string[] args)throwsException { One          AWorkbook wb=NewHssfworkbook ();//to define a new workbook -Wb.createsheet ("first sheet page");//Create a first sheet page -Wb.createsheet ("second sheet page");//Create a second sheet page theFileOutputStream fileout=NewFileOutputStream ("d:\\ with POI sheet page. xls"); - Wb.write (fileout); - fileout.close (); -     } +}

4, create a cell

Demo3.java

1  PackageCom.wishwzp.poi;2 3 ImportJava.io.FileOutputStream;4 5 ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook;6 ImportOrg.apache.poi.ss.usermodel.Cell;7 ImportOrg.apache.poi.ss.usermodel.Row;8 ImportOrg.apache.poi.ss.usermodel.Sheet;9 ImportOrg.apache.poi.ss.usermodel.Workbook;Ten  One  Public classDemo3 { A  -      Public Static voidMain (string[] args)throwsexception{ -Workbook wb=NewHssfworkbook ();//to define a new workbook theSheet Sheet=wb.createsheet ("First Sheet page");//Create a first sheet page -Row row=sheet.createrow (0);//Create a row -          -Cell Cell=row.createcell (0);//Create a cell 1th column +Cell.setcellvalue (1);//set a value for a cell -          +Row.createcell (1). Setcellvalue (1.2);//Create a cell the 2nd column value is 1.2 A          atRow.createcell (2). Setcellvalue ("This is a string type");//Create a cell with the 3rd column value as a string -          -Row.createcell (3). Setcellvalue (false);//Create a cell the 4th column value is a Boolean type -          -FileOutputStream fileout=NewFileOutputStream ("d:\\ Cell.xls with Poi"); - Wb.write (fileout); in fileout.close (); -     } to}

(a) Java uses POI to manipulate excel

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.