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