Oaf_ file Series 11_ implementation OAF read-write Excel Package JXL and POI differences

Source: Internet
Author: User

Advantages:

JXL Chinese support is very good, easy to operate, the method to see the name of the idea.

JXL is a pure javaapi that works perfectly across platforms, and the code can run on Windows or Linux without rewriting

Supports all versions of Excel 95-2000

Generate Excel 2000 Standard format

Supports font, number, date manipulation

Ability to modify cell properties

Supports images and charts, but this set of APIs has limited support for graphs and charts, and only identifies PNG formats.

Disadvantages: Low efficiency, the picture support department is perfect, the support of the format is not as strong as Poi

    1. High efficiency, this is good.
    2. Support formulas, macros, some enterprise applications will be very useful
    3. Ability to modify cell properties
    4. Supports font, number, date manipulation

Disadvantage: Immature, code can not cross the platform, seemingly a lot of peers in the use of the project also met people depressed bug

POI Home: http://poi.apache.org/
JXL's API http://www.andykhan.com/jexcelapi/

    /**      *       */       PackageCom.vteam.mul; ImportJava.io.File; Importjava.io.FileNotFoundException; ImportJava.io.FileOutputStream; Importjava.io.IOException; ImportJXL.      Workbook; ImportJxl.write.Label; ImportJxl.write.WritableSheet; ImportJxl.write.WritableWorkbook; Importjxl.write.WriteException; Importjxl.write.biff.RowsExceededException; ImportOrg.apache.poi.hssf.usermodel.HSSFCell; ImportOrg.apache.poi.hssf.usermodel.HSSFRow; ImportOrg.apache.poi.hssf.usermodel.HSSFSheet; ImportOrg.apache.poi.hssf.usermodel.HSSFWorkbook; /*** @ Author Jarvis * @ Creation Date Dec 2, 2009 * @ Function Test poi JXL Write efficiency*/             Public classTESTPJ { Public intLeng = 6000;//Control Data Volume size         Public intsheet = 2;//control the number of sheet created         Public voidCreatepoi () {Try {                         //Create a new Excel workbookHssfworkbook Newbook =NewHssfworkbook (); intj = 0;  while(J < sheet) {//control the number of sheet createdHssfsheet sheet = newbook.createsheet ("Test" +j); Hssfrow Row=NULL;//Row IndexHssfcell cell1 =NULL;//Column IndexHssfcell cell2 =NULL;//Column Index                     for(inti = 0; I < Leng; i + +) {row=Sheet.createrow (i); Cell1= Row.createcell (0);//Column IndexCell2 = Row.createcell (1);//Column Index                        if(Cell1 = =NULL) {System.out.println ("Cell1 Null"); } cell1.setcelltype (hssfcell.cell_type_string);//defining cells As String typesCell1.setcellvalue ("A Data poi" +i);//enter some content in the cellCell2.setcelltype (hssfcell.cell_type_string);//defining cells As String typesCell2.setcellvalue ("B Data poi" + 1);//enter some content in the cell} J++ ; }                  //Create a new output file streamFileOutputStream fp =NewFileOutputStream ("E:/poi.xls"); Newbook.write (FP);//Save the corresponding Excel workbookFp.flush (); Fp.close ();//end of operation, close file}Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }                }           Public voidCreatejxl () {Try {                  //Open FileWritableworkbook book = Workbook.createworkbook (NewFile ("E:/jxl.xls")); intj = 0 ;  while(J < sheet) {//control the number of sheet createdWritablesheet sheet = book.createsheet ("Test" +j, 0); Label Label1=NULL ; Label Label2=NULL ;  for(inti = 0; i < Leng; i + +) {Label1=NewLabel (0,i, "a data Jxl" +i);//The first parameter is the column index and the second is the row indexLabel2 =NewLabel (1,i, "a data JXL" +i);    Sheet.addcell (Label1); //add a defined cell to a worksheetSheet.addcell (Label2); } J++ ;                  } book.write ();              Book.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(rowsexceededexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(WriteException e) {//TODO auto-generated Catch blockE.printstacktrace (); }              }           Public Static voidMain (string[] args) {Longs =System.currenttimemillis (); TESTPJ T=NewTESTPJ ();              T.createpoi ();              T.CREATEJXL (); LongE =System.currenttimemillis (); System.out.println ("Write Time:" + (E-s)); }            }  

Trial Conclusion:

1. Poi has consumed memory in exchange for some efficiency, while JXL has been very stable in memory consumption. Poi is prone to memory overflow

2.poi as the amount of data increases, the performance is plummeting, and when I increase to 24,000 per sheet, memory overflows. JXL can run it.

It is recommended to use JXL when large data volumes are available. Efficiency and small memory consumption are guaranteed. In the specific development, to some commonly used Excel download, can produce the copy file, avoids the repetitive production Excel consumes the memory

3. During the testing process, the POI was found to be extremely unstable. The data obtained are sometimes very different. For each test case, I repeat the test 4 times and take the average.

Read-http://blog.csdn.net/jarvis_java/article/details/4924099

Write-http://blog.csdn.net/jarvis_java/article/details/4925379

Oaf_ file Series 11_ implementation OAF read-write Excel Package JXL and POI differences

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.