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. 天棋哥哥大战AlphaGo

    天棋哥哥大战AlphaGo Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 20  Solved: 9 [Submit][Status][Web Boa ...

  2. GenericApp SampleApp SimpleAp的区别

    SampleApp3.2 Zigbee2007 协议栈实验例程表演说明C:\Texas Instruments\ZStack-2.0.0-1.2.0\Projects\zstack\Samples\S ...

  3. “找回” Envi 快捷方式

      Envi+IDL文件夹挪到别的电脑,不用安装,直接可以使用.但是桌面和开始菜单没有了Envi,IDL,envi+idl的快捷方式,很不方便.   记录一下快捷方式命令行,备用: envi快捷方式 ...

  4. 转:lr_eval_string函数的用法解析

    在LR中,C的变量和LR的参数是不一样的. 任何C的变量都不能被LR的函数直接调用. 应该用lr_eval_string来取值. 比如{NewParam}(LR中参数化的变量)直接用这个引用是没有问题 ...

  5. hdu_2688_Rotate(树状数组)

    题目连接:hdu_2688_Rotate 题意:给你n数,(n<=3e6),有两个操作,Q为 当前有多少对数,满足严格递增,R l,r为旋转l,r这个区间的数 题解:求严格递增的顺序对我们可以反 ...

  6. CNS数据库网站只用mysql自带的fulltext index功能就可实现了。

    1)编辑脚本script.sql如下 ALTER TABLE `table_name` ADD FULLTEXT (`column_name`) 2)在mysql console下输入命令 SOURC ...

  7. time_wait和clost_wait说明

    在服务器的日常维护过程中,会经常用到下面的命令: netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 它会显示例如 ...

  8. js_设置光标到文本的最后位置

    div_right_table_tr1_td3_input2.focus(function(){ if(input1.setSelectionRange){//火狐 input1.setSelecti ...

  9. POJ 2723 HDU 1816 Get Luffy Out

    二分答案 + 2-SAT验证 #include<cstdio> #include<cstring> #include<cmath> #include<stac ...

  10. JSTL select和checkbox的用法

    select的 用法 <select id="roleIds" name="roleIds" multiple="true" back ...