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"); } }