首页 > 其他 > 详细

通过poi解析excel

时间:2019-12-23 23:01:09      阅读:81      评论:0      收藏:0      [点我收藏+]

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

通过poi解析excel

原文:https://www.cnblogs.com/shouyaya/p/12088864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!