JAVA操作EXCEL两种方法性能对比:POI VS JXL


1.数据准备
      测试环境:WINDOWS XP + HP541
      POI API VERSION:poi 3.7
      JXL API VERSION:jexcelapi-2.6.12
      EXCEL格式:4列文本
      [img][/img]
JAVA操作EXCEL两种方法性能对比:POI VS JXL


2.测试程序:
   POI程序:
    import java.io.FileInputStream;

    import java.util.Date; 

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;

    import org.apache.poi.poifs.filesystem.POIFSFileSystem;

    import org.apache.poi.ss.usermodel.Cell;

    import org.apache.poi.ss.usermodel.Row;

    import org.apache.poi.ss.usermodel.Sheet;

    import org.apache.poi.ss.usermodel.Workbook;

    public class TestPOI {

        public static void read(String pathName) throws Exception {

                Workbook workbook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(pathName)));

                Sheet sheet = workbook.getSheetAt(0); 

                int rows = sheet.getPhysicalNumberOfRows();

                for (int i = 0; i < rows; i++) { 

                        Row rowObj = sheet.getRow(i);

                        for (int j = 0; j < 4; j++) {  

                                Cell cell = rowObj.getCell(j);

                                Object content = cell.getStringCellValue(); 

                                System.out.println("i=" + i + "   j=" + j + "   " +content.toString());

                        }

                } 

        }

        public static void main(String[] args) throws Exception {

                Date date = new Date();

                long dateLong = date.getTime();

                read("D:\\TableInfoFormat.xls");

                Date date1 = new Date();

                long date1Long = date1.getTime();

                System.out.println((date1Long - dateLong) + "ms");

        } 

   }

   //JXL程序:   
   import java.io.FileInputStream;

   import java.io.InputStream;

   import java.util.Date;

   import jxl.Sheet;

   import jxl.Workbook;

   public class TestJxl {

        public static void readExcel1(String pathName) throws Exception { 

                InputStream is = new FileInputStream(pathName);

                Workbook wb = Workbook.getWorkbook(is);

                Sheet sheet = wb.getSheet(0);

                int rows = sheet.getRows(); 

                for (int i = 1; i < rows; i++) { 

                        for (int j = 0; j < 4; j++) { 

                                System.out.println("i=" + i + "   j=" + j + "   " +sheet.getCell(j, i).getContents().trim());

                        }

                }

                is.close();  

        }

        public static void main(String[] args) throws Exception{

                Date date = new Date();

                long dateLong = date.getTime();

                readExcel1("D:\\TableInfoFormat.xls");

                Date date1 = new Date();

                long date1Long = date1.getTime();

                System.out.println((date1Long - dateLong) + "ms");

        }

    }

3.测试结果

类型 数据量(行) 执行时间(ms) 执行时间(ms) 执行时间(ms) 平均时间(ms)
POI 1000 579 562 532 558
JXL 1000 500 469 484 484
POI 5000 984 984 969 979
JXL 5000 922 860 890 891
POI 10000 1609 1594 1641 1615
JXL 10000 1437 1453 1406 1432
POI 30000 3782 3765 3828 3792
JXL 30000 3922 3906 3922 3917
POI 50000 5953 6484 5859 6099
JXL 50000 6765 7421 6984 7057
4.总结
    在小数据量时jxl快于poi,在大数据量时poi要快于jxl。但差距都不明显。

你可能感兴趣的:(java,Excel)