java 操作 excel文件 jxl 与 poi 比较
2016-12-15 10:14
579 查看
[java]
view plain
copy
print?
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Test {
/**
* @param path
*/
public static void readExcelByJXL(String path) {
Workbook book = null;
InputStream input = null;
try {
input = new FileInputStream(path);
book = Workbook.getWorkbook(input);
Sheet sheet = book.getSheet(0);
int columns = sheet.getColumns();
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < columns; j++)
System.out.print(sheet.getCell(j, i).getContents()
+ "\t\t\t\t");
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (book != null)
book.close();
if (input != null)
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param path
*/
public static void readExcelByPOI(String path) {
HSSFWorkbook book = null;
InputStream input = null;
try {
input = new FileInputStream(path);
book = new HSSFWorkbook(input);
HSSFSheet sheet = book.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
int cells = 0;
HSSFRow row = null;
HSSFCell cell = null;
// for (Iterator iterator = sheet.rowIterator();
// iterator.hasNext();) {
// row = (HSSFRow) iterator.next();
for (int i = 0; i < rows; i++) {
row = sheet.getRow(i);
cells = row.getPhysicalNumberOfCells();
// for (Iterator iterator2 = row.cellIterator(); iterator2
// .hasNext();) {
// cell = (HSSFCell) iterator2.next();
for (short j = 0; j < cells; j++) {
cell = row.getCell(j);
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_BLANK:
System.out.print("");
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
System.out.print(cell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
System.out.print(cell.getCellFormula());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
}
System.out.print("\t\t\t\t");
}
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
//测试JXL比POI速度快
long start = System.currentTimeMillis();
readExcelByJXL("c:/questions.xls");
System.out.println("===================AAAAAAAAAAAAAAAa============");
System.out.println(System.currentTimeMillis() - start);
}
}
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
view plain
copy
print?
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Test {
/**
* @param path
*/
public static void readExcelByJXL(String path) {
Workbook book = null;
InputStream input = null;
try {
input = new FileInputStream(path);
book = Workbook.getWorkbook(input);
Sheet sheet = book.getSheet(0);
int columns = sheet.getColumns();
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < columns; j++)
System.out.print(sheet.getCell(j, i).getContents()
+ "\t\t\t\t");
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (book != null)
book.close();
if (input != null)
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param path
*/
public static void readExcelByPOI(String path) {
HSSFWorkbook book = null;
InputStream input = null;
try {
input = new FileInputStream(path);
book = new HSSFWorkbook(input);
HSSFSheet sheet = book.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
int cells = 0;
HSSFRow row = null;
HSSFCell cell = null;
// for (Iterator iterator = sheet.rowIterator();
// iterator.hasNext();) {
// row = (HSSFRow) iterator.next();
for (int i = 0; i < rows; i++) {
row = sheet.getRow(i);
cells = row.getPhysicalNumberOfCells();
// for (Iterator iterator2 = row.cellIterator(); iterator2
// .hasNext();) {
// cell = (HSSFCell) iterator2.next();
for (short j = 0; j < cells; j++) {
cell = row.getCell(j);
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_BLANK:
System.out.print("");
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
System.out.print(cell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
System.out.print(cell.getCellFormula());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
}
System.out.print("\t\t\t\t");
}
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
//测试JXL比POI速度快
long start = System.currentTimeMillis();
readExcelByJXL("c:/questions.xls");
System.out.println("===================AAAAAAAAAAAAAAAa============");
System.out.println(System.currentTimeMillis() - start);
}
}
![](https://oscdn.geek-share.com/Uploads/Images/Content/201701/9cc493f1e15b23d0f4eaea0d0f8b35d0.png)
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import jxl.Sheet; import jxl.Workbook; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class Test { /** * @param path */ public static void readExcelByJXL(String path) { Workbook book = null; InputStream input = null; try { input = new FileInputStream(path); book = Workbook.getWorkbook(input); Sheet sheet = book.getSheet(0); int columns = sheet.getColumns(); for (int i = 0; i < sheet.getRows(); i++) { for (int j = 0; j < columns; j++) System.out.print(sheet.getCell(j, i).getContents() + "\t\t\t\t"); System.out.println(); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (book != null) book.close(); if (input != null) try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * @param path */ public static void readExcelByPOI(String path) { HSSFWorkbook book = null; InputStream input = null; try { input = new FileInputStream(path); book = new HSSFWorkbook(input); HSSFSheet sheet = book.getSheetAt(0); int rows = sheet.getPhysicalNumberOfRows(); int cells = 0; HSSFRow row = null; HSSFCell cell = null; // for (Iterator iterator = sheet.rowIterator(); // iterator.hasNext();) { // row = (HSSFRow) iterator.next(); for (int i = 0; i < rows; i++) { row = sheet.getRow(i); cells = row.getPhysicalNumberOfCells(); // for (Iterator iterator2 = row.cellIterator(); iterator2 // .hasNext();) { // cell = (HSSFCell) iterator2.next(); for (short j = 0; j < cells; j++) { cell = row.getCell(j); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_BLANK: System.out.print(""); break; case HSSFCell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_ERROR: System.out.print(cell.getErrorCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: System.out.print(cell.getCellFormula()); break; case HSSFCell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue()); break; } System.out.print("\t\t\t\t"); } System.out.println(); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (input != null) try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { //测试JXL比POI速度快 long start = System.currentTimeMillis(); readExcelByJXL("c:/questions.xls"); System.out.println("===================AAAAAAAAAAAAAAAa============"); System.out.println(System.currentTimeMillis() - start); } }
相关文章推荐
- Java程序员从笨鸟到菜鸟之(一百零五)java操作office和pdf文件(三)利用jxl实现数据导出excel报表以及与POI的区别
- Java程序员从笨鸟到菜鸟之(一百零五)java操作office和pdf文件(三)利用jxl实现数据导出excel报表以及与POI的区别
- java操作Excel一:POI与JXL的比较
- java操作excel——jxl和poi比较
- java操作Excel效率之poi与fastexcel比较
- java操作Excel--jxl与poj的比较
- POI与JXL 操作excel比较
- Java模块 -- 读取Excel文件写入数据库 Mybatis , POI , JXL
- java中使用JXL对Excel文件进行数据的写入、导出操作
- 基于poi,jxl实现的Java批量写Excel文件模版
- java中使用JXL对Excel文件进行数据的写入、导出操作
- Java生成excel导出文件(使用poi+JXL)
- java操作Excel效率之poi与fastexcel比较(转载)
- POI 与 JXL 的一点比较——关于使用Java操作excel文件
- java操作excel——jxl和poi
- java poi操作excel文件 (新建Excel文件 添加行列、单元格
- Java程序员从笨鸟到菜鸟之(一百零四)java操作office和pdf文件(二)利用POI实现数据导出excel报表
- Java程序员从笨鸟到菜鸟之(一百零四)java操作office和pdf文件(二)利用POI实现数据导出excel报表
- POI与JXL 操作excel比较
- 读取excel文件(jxl.jar包简介/java操作excel jxl.jar下载地址)