日期:2014-05-19 浏览次数:20837 次
public List<HashMap<String, Object>> excuteExcel(InputStream is, int sheetNumber) throws Exception { HSSFWorkbook workbook = new HSSFWorkbook(is); List<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>(); //得到 sheet HSSFSheet sheet = workbook.getSheetAt(sheetNumber); // 一共有 sheet int rowCount = sheet.getLastRowNum(); if (rowCount < 1) { return result; } //得到一个有多少个例 int cellCount = sheet.getRow(0).getLastCellNum(); // 遍历所有的row for (int rowIndex = 0; rowIndex <= rowCount; rowIndex++) { //得到俱体的 HSSFRow row = sheet.getRow(rowIndex); if (null != row) { HashMap<String, Object> rowData = new HashMap<String, Object>(); // 遍历例cell for (short cellIndex = 0; cellIndex < cellCount; cellIndex++) { HSSFCell cell = row.getCell(cellIndex); // 得到例的值 Object cellStr = this.getCellString(cell)==null?"":this.getCellString(cell); String str=cellStr.toString(); if(str!=null){ str=str.replaceAll("'", ""); } rowData.put(String.valueOf(cellIndex), cellStr); } result.add(rowData); } } return result; }