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. Basically Speaking

    Basically Speaking Time Limit: 2 Sec  Memory Limit: 200 MB Submit: 19  Solved: 11 [Submit][Status][W ...

  2. cocos2d-x 3.3 显示中文

    Resources文件夹下的strings.xml: <dict> <key>targetScore</key> <string>目标分数</st ...

  3. ubuntu 12.04 安装snort acidbase相关注意事项

    一.安装Snort 1.安装libpcap 1 apt-get install libpcap-dev 2.安装snort 1 2 apt-get install snort apt-get inst ...

  4. 编辑距离算法详解:Levenshtein Distance算法

    算法基本原理:假设我们可以使用d[ i , j ]个步骤(可以使用一个二维数组保存这个值),表示将串s[ 1…i ] 转换为 串t [ 1…j ]所需要的最少步骤个数,那么,在最基本的情况下,即在i等 ...

  5. 优化viewHolder

  6. ZOJ 3913 Bob wants to pour water

    ZOJ Monthly, October 2015 K题 二分答案+验证 #include<iostream> #include<algorithm> #include< ...

  7. Linux 监控文件事件

    某些应用程序需要对文件或者目录进行监控,来侦测其是否发生了某些事件.Linux很贴心的为我们提供了inotify API,也是Linux的专有. inotify API 在使用之前一定要有一个inot ...

  8. Linux 部署 Tomcat和JDK

    一:安装jdk下载将jdk加压后放到/usr/local目录下: [root@master ~]#chmod 755 jdk-6u5-linux-x64.bin [root@master ~]# ./ ...

  9. Application对象

    Application对象报讯是应用程序参数的额,多个用户可以共享一个Application.用于启动和管理ASP.NET应用程序. Count  属性 获取Application对象变量的个数,集合 ...

  10. ARMs3c2440开发板挂接NFS服务

    1.修改IP地址,使虚拟机,电脑PC机.开发板位于同一个网段,开发板网线与电脑网络接口连接,如PC:ip 192.168.0.112 255.255.255.0 虚拟机 192.168.0.8 255 ...