`
zzzwp
  • 浏览: 19909 次
社区版块
存档分类
最新评论

POI使用笔记

阅读更多

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() + "";

}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics