java 解析不了数据_JAVA 解析Excel数据

();

// 获得本行中单元格的个数

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();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值