zoukankan      html  css  js  c++  java
  • 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(); } }
  • 相关阅读:
    Tensorflow CIFAR10 (二分类)
    2018年阿里巴巴重要开源项目汇总
    环境变量备份
    ubuntu Qt5 librealsense opencv
    ubuntu16.04 qt opencv3.4
    时间作为文件名
    ubuntu16.04 安装opencv3
    Visual studio 2015/2017 opencv3.4 kineck2.0 osg realsense配置
    开源监控系统整合Nagios+Cacti+Nconf详解
    nagios系列(八)之nagios通过nsclient监控windows主机
  • 原文地址:https://www.cnblogs.com/ry123/p/3863420.html
Copyright © 2011-2022 走看看