1、添加相应的jar包
2、使用方法如下:
Workbook workbook= WorkbookFactory.create(new File("f:/upload/"+fileName)); //创建Workbook对象来解析对应的excel Sheet sheet=workbook.getSheetAt(0); //通过索引找到相应的sheet int rownum=sheet.getLastRowNum(); //找到最后一行 for (int i = 1; i <=rownum; i++) { //遍历每一行 Row row=sheet.getRow(i); //通过Row对象得到行的数据 Student student=new Student(); //通过student对解析到的数据进行封装 student.setName(row.getCell(0).getStringCellValue()); //对获取的数据设置相应的格式 student.setAge((int)row.getCell(1).getNumericCellValue()); student.setDate(row.getCell(2).getDateCellValue()); studentList.add(student);