首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > VSTS >

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

2012-10-08 
JAVA操作EXCEL两种方法性能对比:POI VS JXL1.数据准备测试环境:WINDOWS XP + HP541POI API VERSION:poi 3.

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]



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)
POI1000579562532558
JXL1000500469484484
POI5000984984969979
JXL5000922860890891
POI100001609159416411615
JXL100001437145314061432
POI300003782376538283792
JXL300003922390639223917
POI500005953648458596099
JXL500006765742169847057
4.总结
    在小数据量时jxl快于poi,在大数据量时poi要快于jxl。但差距都不明显。

热点排行