POI 讀取EXCEL

/**
* 獲取單元格數值

* @param cell
* @return
*/
private String getCellValue(Cell cell) {


String cellValue = "";


DecimalFormat df = new DecimalFormat("#.00");


switch (cell.getCellType()) {


case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString().trim();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = df.format(cell.getNumericCellValue()).toString();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue()).trim();
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellValue = cell.getCellFormula();
break;
default:
cellValue = "";
}


return cellValue;
}
posted @ 2017-11-10 15:33  Duke-码动青春  阅读(146)  评论(0编辑  收藏  举报