Java中导入Excel文件

public List<GbHoInfo> loadScoreInfo(String xlsPath) throws IOException{
        List<GbHoInfo> temp = new ArrayList<GbHoInfo>();
        FileInputStream fileIn = new FileInputStream(xlsPath);
        //根据指定的文件输入流导入Excel从而产生Workbook对象
        Workbook wb0 = new HSSFWorkbook(fileIn);
        //获取Excel文档中的第一个表单
        Sheet sht0 = wb0.getSheetAt(0);
            //对Sheet中的每一行进行迭代
            for (Row r : sht0) {
                //如果当前行的行号(从0开始)未达到2(第三行)则从新循环
                if(r.getRowNum()<1){
                    continue;
                }
                //创建实体类
                GbHoInfo info=new GbHoInfo();
                //取出当前行第1个单元格数据,并封装在info实体stuName属性上
                r.getCell(29).setCellType(Cell.CELL_TYPE_STRING);
                //int cellType = r.getCell(29).getCellType();
                String stringCellValue = r.getCell(29).getStringCellValue();
                info.setId(Integer.parseInt(r.getCell(0).getStringCellValue()));
                info.setPropArea(Float.parseFloat(stringCellValue));
                temp.add(info);
            }
        fileIn.close();    
        return temp;    
    }

...................................

原文地址:https://www.cnblogs.com/wuhu/p/9050960.html