java学习(四) excel读取
2014-07-23 16:49
302 查看
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(); } }
相关文章推荐
- 生成/读取(反向更新数据库) Excel文件(示例代码下载)
- 从Excel文件读取数据表
- asp读取excel表名的实现代码
- Java读取Excel文件中的数据
- 读取Excel和出错时的解决
- OLDB读取excel的数据类型不匹配的解决方案【转】
- 一个读取EXCEL问题的解决
- C#读取Excel
- 【python】读取excel文件
- c#读取excel中的数据(winform)
- java读取excel的内容 的代码示例
- Python读取Excel表格,并同时画折线图和柱状图的方法
- JAVA poi 读取excel 通用模板
- Java使用poi读取excel数据(excel可能很大,先转换为csv再读取)
- 用Java POI操作Excel,读取数据导入DB2数据库
- 读取Excel文件到数据库
- DataTable To Excel File,Create Excel, Create Local Floder 从数据库中读取数据存到本地指定文件夹的Excel中
- Ado.Net读取Excel常见问题总结
- EXCEL的简单读取
- 利用OpenXml读取、导出Excel