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学习(四) excel读取的更多相关文章

  1. Java学习-017-EXCEL 文件读取实例源代码

    众所周知,EXCEL 也是软件测试开发过程中,常用的数据文件导入导出时的类型文件之一,此文主要讲述如何通过 EXCEL 文件中 Sheet 的索引(index)或者 Sheet 名称获取文件中对应 S ...

  2. Java学习-019-Properties 文件读取实例源代码

    在这几天的学习过程中,有开发的朋友告知我,每个编程语言基本都有相应的配置文件支持类,像 Python 编程语言中支持的 ini 文件及其对应的配置文件读取类 ConfigParse,通过这个类,用户可 ...

  3. Java学习-016-CSV 文件读取实例源代码

    上文(CSV文件写入)讲述了日常自动化测试过程中将测试数据写入 CSV 文件的源码,此文主要讲述如何从 CSV 文件获取测试过程中所需的参数化数据.敬请各位小主参阅,若有不足之处,敬请大神指正,不胜感 ...

  4. Java POI 操作Excel(读取/写入)

    pom.xml依赖: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi< ...

  5. JAVA学习<四>

    一. 数组: Java 中操作数组只需要四个步骤: 1. 声明数组 语法:  数据类型[ ] 数组名: 或者   数据类型 数组名[ ]: 其中,数组名可以是任意合法的变量名. 2. 分配空间 简单地 ...

  6. Java学习笔记——JDBC读取properties属性文件

    Java 中的 properties 文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件. 文件的内容是格式是"键=值"(key-valu ...

  7. Java 学习笔记之读取jdbc.propertyes配置参数

    package test; import java.io.IOException; import java.io.InputStream; import java.util.Properties; p ...

  8. Java学习 (四)基础篇 Java基础语法

    注释&标识符&关键字 注释 注释并不会被执行,其主要目的用于解释当前代码 书写注释是一个非常好的习惯,大厂要求之一 public class hello { public static ...

  9. java学习(二)--excel导出

    public static String writeFile(String fileName, String[][] content) { WritableWorkbook wwb = null; S ...

随机推荐

  1. 5--OC--构造方法

    //  Created by Stephen on 16/3/2.//  Copyright © 2016年 Stephen. All rights reserved.//// 回顾上一章节Perso ...

  2. 使用log4j无法输出日志

    前段时间在项目的过程中使用log4j来输出日志,但是在一个项目里我明明已经在src/main/resource目录下创建了log4j.properties.具体配置如下: log4j.rootLogg ...

  3. android webview处理下载内容

    url = "http://m.mumayi.com/"; WebView = (WebView) findViewById(R.id.webView1); WebView.get ...

  4. ecshop后台增加模块菜单项详细教程(图文)

    有的时候我们会在后台增加新的功能,菜单项是一个程序的入口,是必不可少的,如何在后台增加菜单项呢,大家可以参考下面的教程:   例如:想在后台左侧的菜单栏的"促销管理"下添加一个&q ...

  5. DNS开源服务器BIND最小配置详解<转>

    一,简介 相对于存储和大数据领域,CDN是一个相对小的领域,但行行出状元,BIND就是CDN领域的蝉联N届的状元郎.BIND是一款非常常用的DNS开源服务器,全球有90%的DNS用BIND实现.值得一 ...

  6. Allocation Failure

    up vote 8 down vote accepted "Allocation Failure" is a cause of GC cycle to kick. "Al ...

  7. 页面新宠图片格式WebP

    WebP格式,谷歌(google)开发的一种旨在加快图片加载速度的图片格式.图片压缩体积大约只有JPEG的2/3,并能节省大量的服务器带宽资源和数据空间.Facebook Ebay等知名网站已经开始测 ...

  8. POJ1611 The Suspects 并查集模板题

    题目大意:中文题不多说了 题目思路:将每一个可能患病的人纳入同一个集合,然后遍历查找每个点,如果改点点的根节点和0号学生的根节点相同,则该点可能是病人. 模板题并没有思路上的困难,只不过在遍历时需要额 ...

  9. Android Fragment 真正的完全解析(下)---转

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37992017 上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和 ...

  10. Struts2.3.16日志(中)

    Result Configuration --Result 配置 当一个操作类方法完成后,它将返回一个字符串.字符串的值是用来选择一个元素的结果.一个操作映射的结果往往会有一组代表不同的可能的结果.一 ...