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

 }

posted @ 2016-06-15 10:56  N神3  阅读(219)  评论(0编辑  收藏  举报