POI Excel 셀 값 가져오기

3171 단어 실전편
    public String getCellValue(XSSFCell cell) {
        String value = "";
        //  
        switch (cell.getCellType()) {
        case HSSFCell.CELL_TYPE_NUMERIC:
            value = cell.getNumericCellValue() + "";
            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                Date date = cell.getDateCellValue();
                if (date != null) {
                    value = new SimpleDateFormat("yyyy-MM-dd").format(date);
                } else {
                    value = "";
                }
            } else {
                value = new DecimalFormat("0").format(cell.getNumericCellValue());
            }
            break;
        case HSSFCell.CELL_TYPE_STRING: //  
            value = cell.getStringCellValue();
            break;
        case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
            value = cell.getBooleanCellValue() + "";
            break;
        case HSSFCell.CELL_TYPE_FORMULA: //  
            value = cell.getCellFormula() + "";
            break;
        case HSSFCell.CELL_TYPE_BLANK: //  
            value = "";
            break;
        case HSSFCell.CELL_TYPE_ERROR: //  
            value = " ";
            break;
        default:
            value = " ";
            break;
        }
        return value;
    }

좋은 웹페이지 즐겨찾기