• java学习(四) excel读取


    private static void readExcel() {
            String filePath = "C:/Standardzid.xls";
            File file = new File(filePath);
            List<String> citys = new ArrayList<String>();
            List<LandPropertyType> cityList = null;
            List<List<LandPropertyType>> propertys = null;
            try {
                POIFSFileSystem readPoiFileSystem = new POIFSFileSystem(new FileInputStream(file));
                HSSFWorkbook workbook = new HSSFWorkbook(readPoiFileSystem);
                HSSFSheet sheet = workbook.getSheetAt(0);
                boolean flag = true;
                for (Row row : sheet) {
                    if (flag) {
                        for (Cell cell : row) {
                            String cityName = cell.getStringCellValue();
                            if (cityName != null && cityName.length() > 0) {
                                citys.add(cityName);
                            }
                            propertys = new ArrayList<List<LandPropertyType>>();
                            for (int i = 0; i < citys.size(); i++) {
                                cityList = new ArrayList<LandPropertyType>();
                                propertys.add(cityList);
                            }
                        }
                        flag = false;
                    } else {
                        String propertyType = row.getCell(0).getStringCellValue();
                        int lastCell = row.getLastCellNum();
                        for (int i = 2; i < lastCell; i++) {
                            Cell cell=row.getCell(i);
                            if(cell!=null){
                                String propertyName = row.getCell(i).getStringCellValue();
                                if (propertyName != null && propertyName.length() > 0) {
                                    String[] propertyNames = propertyName.split(",");
                                    for (String name : propertyNames) {
                                        LandPropertyType landPropertyType = new LandPropertyType(name,LandProperty.valueOf(propertyType));
                                        propertys.get(i - 2).add(landPropertyType);
                                    }
                                }
                            }
                        }
                    }
                }
                for (int i = 0; i < citys.size(); i++) {
                    String city = citys.get(i);
                    LandPropertyType[] newLandPropertys = new LandPropertyType[propertys.size()];
                    propertyMap.put(city, propertys.get(i).toArray(newLandPropertys));
                }
                
    } catch (Exception e) { e.printStackTrace(); } }
  • 相关阅读:
    java web spring challenge01
    eclipse的一个小失误
    创建线程的方式三:实现Callable接口。 --- JDK 5.0新增
    线程通信的应用:经典例题:生产者/消费者问题
    8.5 练习
    8.4 练习1
    LockTest.java
    DeadLock.java
    线程死锁
    使用同步机制将单例模式中的懒汉式改写为线程安全的
  • 原文地址:https://www.cnblogs.com/ry123/p/3863420.html
Copyright © 2020-2023  润新知