ひがやすを技術ブログ

電通国際情報サービスのプログラマ

HSSFCellによる型の判定

HSSFCellによる型の判定はこんな感じ。


private Object getValue(HSSFCell cell) {
if (cell == null) {
return null;
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC :
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
}
return new BigDecimal(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING :
return cell.getStringCellValue().trim();
case HSSFCell.CELL_TYPE_BLANK :
return null;
default :
return cell.getStringCellValue().trim();
}
}
trim()は入れたくないけど、なぜか最後にブランクが入る場合が!