poi excel 操作,读取导入excel各行cell值,并保存至实体类

private boolean importAll(File file){
try{
InputStream input = null;
try {
input = new FileInputStream(excel);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(input == null){
return false;
}
HSSFWorkbook wb = null;
try {
wb = new HSSFWorkbook(input);
} catch (IOException e) {
e.printStackTrace();
}
if(wb == null){
return false;
}
Sheet sheet = wb.getSheet("全部专家信息");
int totalRow = sheet.getPhysicalNumberOfRows();//总行数,从1开始计数
int rowIndex = 2;//从第二行开始读
for(int i=rowIndex; i<totalRow; i++){
Row row = sheet.getRow(i);
Expert e = new Expert();
e.setName(row.getCell(1).getStringCellValue());
e.setTitle(row.getCell(2).getStringCellValue());
e.setWorkunit(row.getCell(3).getStringCellValue());
e.setIdnumber(row.getCell(4).getStringCellValue());
e.setAddress(row.getCell(5).getStringCellValue());
e.setZipcode(row.getCell(6).getStringCellValue());
e.setEmail(row.getCell(7).getStringCellValue());
e.setTelephone(row.getCell(8).getStringCellValue());
e.setRemark(row.getCell(9).getStringCellValue());
e.setOrg_category(row.getCell(10).getStringCellValue());
e.setCon_category(row.getCell(11).getStringCellValue());
e.setOth_category(row.getCell(12).getStringCellValue());
e.setTag(row.getCell(13).getStringCellValue());
expertDao.add(e);
}
return true;
}catch(Exception e){
e.printStackTrace();
return false;
//处理导入异常
}
}

你可能感兴趣的:(poi excel 操作,读取导入excel各行cell值,并保存至实体类)