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