POI导入
public void import(){
XSSFWorkbook wb = new XSSFWorkbook(new File("filePath"));
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow headRow = sheet.getRow(0);
int colNum = headRow.getLastCellNum();
int rowNum=sheet.getLastRowNum();
for (int i = 0; i < rowNum; i++) { //读取excel文件和创建对象/持久化对象
Person person= new Person();
for(int j = 0;j<colNum;j++){
XSSFCell cell = row.getCell(0);
String value = cell.getStringCellValue();
person.setId(i+1);
person.setName(value);
}
person.save();
}
}
感谢您的阅读,您的支持是我写博客动力。