static String toValue ( Cell cell , List < CellProcessor > cellProcessors ) { String value ; switch ( cell . getCellTypeEnum ( ) ) { case BLANK : value = null ; break ; case STRING : value = cell . getStringCellValue ( ) ; break ; case NUMERIC : if ( DateUtil . isCellDateFormatted ( cell ) ) { try { // Excel dates are LocalDateTime, stored without timezone. // Interpret them as UTC to prevent ambiguous DST overlaps which happen in other // timezones. LocaleUtil . setUserTimeZone ( LocaleUtil . TIMEZONE_UTC ) ; Date dateCellValue = cell . getDateCellValue ( ) ; value = formatUTCDateAsLocalDateTime ( dateCellValue ) ; } finally { LocaleUtil . resetUserTimeZone ( ) ; } } else { // excel stores integer values as double values // read an integer if the double value equals the // integer value double x = cell . getNumericCellValue ( ) ; if ( x == Math . rint ( x ) && ! Double . isNaN ( x ) && ! Double . isInfinite ( x ) ) value = String . valueOf ( ( long ) x ) ; else value = String . valueOf ( x ) ; } break ; case BOOLEAN : value = String . valueOf ( cell . getBooleanCellValue ( ) ) ; break ; case FORMULA : // evaluate formula FormulaEvaluator evaluator = cell . getSheet ( ) . getWorkbook ( ) . getCreationHelper ( ) . createFormulaEvaluator ( ) ; CellValue cellValue ; try { cellValue = evaluator . evaluate ( cell ) ; } catch ( StackOverflowError e ) { LOG . error ( "StackOverflowError evaluating formula" , e ) ; throw new RuntimeException ( "Error evaluating formula, possibly due to deep formula nesting." ) ; } switch ( cellValue . getCellTypeEnum ( ) ) { case BOOLEAN : value = String . valueOf ( cellValue . getBooleanValue ( ) ) ; break ; case NUMERIC : if ( DateUtil . isCellDateFormatted ( cell ) ) { try { // Excel dates are LocalDateTime, stored without timezone. // Interpret them as UTC to prevent ambiguous DST overlaps which happen in other // timezones. LocaleUtil . setUserTimeZone ( LocaleUtil . TIMEZONE_UTC ) ; Date javaDate = DateUtil . getJavaDate ( cellValue . getNumberValue ( ) , false ) ; value = formatUTCDateAsLocalDateTime ( javaDate ) ; } finally { LocaleUtil . resetUserTimeZone ( ) ; } } else { // excel stores integer values as double values // read an integer if the double value equals the // integer value double x = cellValue . getNumberValue ( ) ; if ( x == Math . rint ( x ) && ! Double . isNaN ( x ) && ! Double . isInfinite ( x ) ) value = String . valueOf ( ( long ) x ) ; else value = String . valueOf ( x ) ; } break ; case STRING : value = cellValue . getStringValue ( ) ; break ; case BLANK : value = null ; break ; default : throw new MolgenisDataException ( "unsupported cell type: " + cellValue . getCellTypeEnum ( ) ) ; } break ; default : throw new MolgenisDataException ( "unsupported cell type: " + cell . getCellTypeEnum ( ) ) ; } return AbstractCellProcessor . processCell ( value , false , cellProcessors ) ; }
Gets a cell value as String and process the value with the given cellProcessors