java使用poi读取Excel2003版(.xls)
File file = new file("D:\\test.xls");
FileInputStream fis = new FileInputStream(file);
HSSFWorkbook book = new HSSFWorkbook(fis);
HSSFSheet sheet = book.getSheetAt(0);
int rows = sheet.getLastRowNum();
for (int i = 1; i < rows; i++) {
HSSFRow row = sheet.getRow(i);// 行数
if(row.getCell(0) == null){//姓名为空的行跳过
continue;
}else if(row.getCell(1) == null){//学籍号为空的行跳过
continue;
}else{
String studentName = row.getCell(0).getStringCellValue();
String rollCode = row.getCell(1).getStringCellValue();
//如果单元格设置了数值,但是数据库字段是String,那么要获取String类型的数值就需要转化
if(row.getCell(2)!=null){
row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
}
String className = row.getCell(2).getStringCellValue();
double height = row.getCell(3).getNumericCellValue();
double weight = row.getCell(4).getNumericCellValue();
int pulse = (int) row.getCell(5).getNumericCellValue();
}
}