();
// 获得本行中单元格的个数
int cellCount = row.getLastCellNum();
// 遍历列cell
for (short cellIndex = 0; cellIndex < cellCount;
cellIndex++) {
XSSFCell cell = row.getCell(cellIndex);
// 获得指定单元格中的数据
Object cellStr = this.getCellString(cell);
rowData.add(cellStr);
}
result.add(rowData);
}
}
return result;
}
private Object getCellString(XSSFCell cell) {
Object result = null;
if (cell != null) {
//
单元格类型:Numeric:0,String:1,Formula:2,Blank:3,Boolean:4,Error:5
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_STRING:
result = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
result = null;
break;
case HSSFCell.CELL_TYPE_ERROR:
result = null;
break;
default:
System.out.println("枚举了所有类型");
break;
}
}
return result;
}
public static List getDatas(File file)throws Exception{
ExcelSheetParser parser = new ExcelSheetParser(file);
List datas = parser.getDatasInSheet(0);
return datas;
}
public static void main(String[] args) {
File file = new File("C:\\load.xls");
ExcelSheetParser parser = new ExcelSheetParser(file);
List datas = parser.getDatasInSheet(0);
for (int i = 0; i < datas.size(); i++) {
List row = datas.get(i);
for (short j = 0; j < row.size(); j++) {
Object value = row.get(j);
String data = String.valueOf(value);
System.out.print(data + "\t");
}
System.out.println();
}
}
}