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. 学习笔记——抽象工厂模式Abstract Factory

    在工厂模式的基础上,通过为工厂类增加接口,实现其他产品的生产,而不用一类产品就增加一个工厂. 依然以<真菌世界>游戏故事类比,树作为工厂,如果现在有两类树,一类生产快速弄真菌飞机和20毫米 ...

  2. linux的mount(挂载)NFS 共享,命令详解

    Linux下挂载(mount)光盘镜像文件.移动硬盘.U盘.Windows和NFS网络共享 linux是一个优秀的开放源码的操作系统,可以运行在大到巨型小到掌上型各类计算机系统上,随着 linux系统 ...

  3. struts2 严重: Error filterStart 原因

    当然你也可以用最新的struts2.3,把相应的包拷贝到工作区lib里 使用struts2.3.1所需的JAR包commons-fileupload-1.2.2.jarcommons-logging- ...

  4. Ubuntu系统搭建PPTP,VPN

    1.先安装pptp apt-get install pptpd 2.打开pptp的DNS vim /etc/ppp/option.pptpd 去掉下面两行内容前的# ms-dns 8.8.8.8 ms ...

  5. centos minimal Bind 主从服务器部署

    实验环境 两台虚拟机BindM和BindS,装的系统都是centos6.3 minimal   IP地址 主机名hostname 主DNS服务器 192.168.137.102 bindm.cas.c ...

  6. CentOS 系统中安装postfix+dovecot+openwebmail <转>

    一.先卸载sendmain[root@ser ~]#  yum remove sendmail 二.安装postfix ,dovecot,cyrus-sasl[root@ser ~]#  yum -y ...

  7. C# 双引号的输出

    Console.WriteLine("\"a little list.\"");

  8. 白话解释IIS并发连接数

    做负载均衡的时候会发现有很多并发数的参数.其中有一个"IIS并发连接数"是我们要关注的. 假设"IIS并发连接数"显示为1000,这并不代表有1000个客户端在 ...

  9. dom4j解析xml实例(2)

    dom4j是一个java的XML API,类似jdom,用来读写XML文件,它性能优异.功能强大和极易使用等特点 所用jar包:dom4j-1.6.1.jar.jaxen-1.1-beta-6.jar ...

  10. iOS开发中控制器切换方式Modal

    简介 在iPhone开发中 Modal是一种常见的切换控制器的方式 默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 在iPad开发中 Modal的使用频率也是非常高的 对比iPhone开发,Mo ...