Seventh week job POI Operations Excel,world documentation

Source: Internet
Author: User

First of all, the difference between JXL and POI.

The same point is a tool to operate Excel, but JXL is not commonly used for reasons such as: JXL no one to maintain, the operation of Excel ineffective, only support 03 and its previous version of Excel, the image support is not complete.

Compared to POI, the POI is highly efficient and supports all versions with Xlsx,xls support. And the operation of big data efficiency is relatively high, because he has made a corresponding optimization of the operation of big data.

Here's a simple implementation: POI operations Excel features

Simple unit Test class: The function of implementation is to write data to an Excel file

1 @Test2      Public voidTest1 ()throwsIOException3     {4         //1. Create a workbook5Hssfworkbook hssfworkbook=NewHssfworkbook ();6         //2. Create a worksheet7Hssfsheet Sheet=hssfworkbook.createsheet ("Sunnerr");8         9         //3. Create line HssfrowTenHssfrow Hssfrow=sheet.createrow (3); OneHssfcell Hssfcell=hssfrow.createcell (3); A         //4. Create a cell -Hssfcell.setcellvalue ("haha haha"); -         //output to Hard disk theFileOutputStream fileoutputstream=NewFileOutputStream ("d:\\log\\ test. xlsx"); -         //output Excel to a specific address - Hssfworkbook.write (fileoutputstream); -          + hssfworkbook.close (); - fileoutputstream.close (); +     } A     
View Code

Results The corresponding data is available in the courseware Excel. The corresponding thing has been written

Next is a simple reading of the data:

1 /*2 * Steps to test read3      */4 @Test5      Public voidTest2 ()throwsIOException6     {7FileInputStream inputstream=NewFileInputStream ("d:\\log\\ test. xlsx");8         //1. Reading workbooks9Hssfworkbook hssfworkbook=NewHssfworkbook (inputstream);Ten         //2. Read the first worksheet OneHssfsheet Sheet=hssfworkbook.getsheetat (0); A         //4. Reading cells -Hssfrow Hssfrow=sheet.getrow (3); -Hssfcell Cell=hssfrow.getcell (3); the System.out.println (Cell.getstringcellvalue ()); -          - hssfworkbook.close (); - inputstream.close (); +}
View Code

The operation results are as follows

The next step is to simply fill in the colors and their merged cells:

1 /*2 * Steps to test read3      */4 @Test5      Public voidTest2 ()throwsIOException6     {7FileInputStream inputstream=NewFileInputStream ("d:\\log\\ test. xlsx");8         //1. Reading workbooks9Hssfworkbook hssfworkbook=NewHssfworkbook (inputstream);Ten         //2. Read the first worksheet OneHssfsheet Sheet=hssfworkbook.getsheetat (0); A         //4. Reading cells -Hssfrow Hssfrow=sheet.getrow (3); -Hssfcell Cell=hssfrow.getcell (3); the System.out.println (Cell.getstringcellvalue ()); -          - hssfworkbook.close (); - inputstream.close (); +}
View Code

Successful merge succeeded after opening file, color fill succeeded

Poi operations Excel is sometimes used in projects.

Seventh week job POI Operations Excel,world documentation

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.