poi读取数据的时候空格,字符数据,数字类型数据处理方式
logger.info("============ExeclReader.readExeclToMapList() begin===========");
try {
for (int i = st.getFirstRowNum(); i <= st.getLastRowNum(); i++) {
row=st.getRow(i);
List<HashMap<String, String>> rowMap = new ArrayList<HashMap<String,String>>();
for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) {
HashMap<String,String> cellMap = new HashMap<String, String>();
cellMap.put("rowNum", String.valueOf(i+1));
cellMap.put("ColumnNum", String.valueOf(j+1));
//if(row.getCell(j).getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
// cellMap.put("val", String.valueOf((int)Math.floor(row.getCell(j).getNumericCellValue())));
//}else{
if(row.getCell((short) j).getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
BigDecimal bd = new BigDecimal(row.getCell((short) j).getNumericCellValue());
String val= bd.toPlainString();
if(val.indexOf(".0") > 0){
val = val.substring(0,val.indexOf(".0")).trim();
}
cellMap.put("val", val);
}else{
cellMap.put("val", StringUtil.trim(row.getCell((short)j)==null?"":row.getCell((short)j).getStringCellValue()));
}
//}
rowMap.add(cellMap);
}
dataMap.add(rowMap);
}
} catch (Exception e) {
e.printStackTrace();
throw new Exception("读取execl 数据异常,请检查!!!");
}
logger.info("============ExeclReader.readExeclToMapList() end===========");