您的位置:首页 > 其它

POI使用笔记

2016-06-20 15:19 260 查看

1、获取单元格中的值

 

public String getStringValue(HSSFCell cell) {

if (cell == null)

return "";

switch (cell.getCellType()) {

case HSSFCell.CELL_TYPE_BLANK:

return "";

case HSSFCell.CELL_TYPE_BOOLEAN:

return cell.getBooleanCellValue() + "";

case HSSFCell.CELL_TYPE_NUMERIC: {

if (HSSFDateUtil.isCellDateFormatted(cell)) {

SimpleDateFormat sdf = new SimpleDateFormat(

"yyyy-MM-dd HH:mm:ss");

return sdf.format(cell.getDateCellValue());

} else {

double tmp = cell.getNumericCellValue();

if (tmp % (int) tmp == 0) {

return "" + (int) tmp;

}

return tmp + "";

}

}

case HSSFCell.CELL_TYPE_STRING:

return cell.getStringCellValue();

case HSSFCell.CELL_TYPE_FORMULA:

return cell.getCellFormula();

default:

return cell.getErrorCellValue() + "";

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: