通过poi解析excel


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM