• poi 读取 excel (.xls) 97-2003


    1.sh.getLastRowNum() 比行数少1

    private List<Map>  getData(File file) throws Exception{
            List<Map> list = new ArrayList<Map>(); //存放excel的data 每个list是sheet
            
            //获取IO流
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            //打开HSSFWorkbook
            POIFSFileSystem fs = new POIFSFileSystem(in);
            HSSFWorkbook wb = new HSSFWorkbook(fs);//获取HSSWorkbook
            int sheetsNum = wb.getNumberOfSheets();//excel sheet
            //解析sheet的数据
            for(int i = 0 ; i < sheetsNum ; i++){
                Map map = new HashMap();
                HSSFSheet sh = wb.getSheetAt(i);//得到sheet
                //解析行
                int columnNum = 0;
                for(int j = 0 ; j <= sh.getLastRowNum() ; j++){
                    HSSFRow row = sh.getRow(j);
                    //解析列
                    for(int z = 0; z < row.getLastCellNum(); z++){
                        HSSFCell cell = row.getCell(z);
                        
                        if(cell != null){
                            if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
                                 map.put(j + "" + z, cell.getNumericCellValue());
                            }
                            if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){
                                 map.put(j + "" + z, cell.getStringCellValue());
                            }
                        }
                    }
                    columnNum = row.getLastCellNum();
                }
                if(sh.getLastRowNum() != 0 && columnNum != 0){
                    map.put("rowNum" ,sh.getLastRowNum() + 1);
                    map.put("columnNum", columnNum);
                    list.add(map);
                }
            }
            return list;
        }
  • 相关阅读:
    GIt-重置
    Git-对象
    Git-暂存区
    Git-Git初始化
    Git-起步
    调试九法-制造失败
    调试九法-理解系统
    readhat7.0 bond配置
    firewall-cmd 防火墙命令详解 及 TCP Wrappers
    RAID与LVM磁盘阵列技术
  • 原文地址:https://www.cnblogs.com/jinTaylor/p/4277259.html
Copyright © 2020-2023  润新知