jxl读取excel

来源:百度知道 编辑:UC知道 时间:2024/06/27 12:31:01
用jxl读取excel 中的数据,并将数据导入到数据库中,
因为考虑到 内存占用大的问题,本人作了如下设计:

分批量读取 excel的数据,然后插入数据库。
如: 读取 100行 excel的数据, 然后插入数据库,然后关闭 Workbook

再读取100行 .... 再插入... 再关闭,

如此循环......

请教高手,如何实现.

用POI吧,效率,内存占用比jxl要好。

自己网上找资料吧,用法很简单。

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class JxlUtil {

public static String getTelnoFromXSL(int rowid, int fromrowno,
String xlspath) {

Workbook book = null;
try {
book = Workbook.getWorkbook(new java.io.File(xlspath));
} catch (BiffException ex) {
System.out.println("Read Excel file failed!");
System.out.println("File name: " + xlspath);
System.exit(0);

} catch (IOException ex) {
System.out.println("Read Excel file failed!");
System.out.println("File name: " + xlspath);
System.exit(0);

}

// get sheet object
Sheet sheet = book.getSheet(0);
String result;
int i = 0;
int rowcnt = sheet.getRows();
String[] telstr;
if(fromrowno+10