與寫(xiě)對(duì)應(yīng)的是讀.
package net.blogjava.chenlb;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
* jxl 的Excel閱讀器.
* @author chenlb 2007-10-20 下午01:36:01
*/
public class JxlExcelReader {
/**
* @return 返回String[] 的列表
*/
public List readExcel(InputStream in) {
List lt = new ArrayList();
Workbook wb = null;
try {
wb = Workbook.getWorkbook(in);
Sheet[] sheets = wb.getSheets(); //獲取工作
for(int i=0; i<sheets.length; i++) {
Sheet sheet = sheets[i];
for(int j=0; j<sheet.getRows(); j++) {
Cell[] cells = sheet.getRow(j); //讀取一行
if(cells != null && cells.length > 0) { //這一行有內(nèi)容才添加
String[] dataCells = new String[cells.length];
for(int k=0; k<cells.length; k++) {
dataCells[k] = ""+cells[k].getContents(); //讀內(nèi)容
}//column
lt.add(dataCells);
}
}//one sheet
}//xls file
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(wb != null) {
wb.close();
}
}
return lt;
}
}
posted on 2007-10-29 11:04
流浪汗 閱讀(1004)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
JAVA/J2EE