Example usage for org.apache.poi.ss.format CellDateFormatter CellDateFormatter

List of usage examples for org.apache.poi.ss.format CellDateFormatter CellDateFormatter

Introduction

In this page you can find the example usage for org.apache.poi.ss.format CellDateFormatter CellDateFormatter.

Prototype

public CellDateFormatter(String format) 

Source Link

Document

Creates a new date formatter with the given specification.

Usage

From source file:edu.si.sidora.excel2tabular.TabularCell.java

License:Apache License

@Override
public String toString() {
    if (cell == null) {
        return EMPTY_STRING;
    }//from  ww w. j  a  va2 s .c  o  m
    final int cellType = cell.getCellType();
    switch (cellType) {
    case CELL_TYPE_NUMERIC: {
        if (isCellDateFormatted(cell)) {
            final Date date = getJavaDate(cell.getNumericCellValue());
            final String dateFmt = cell.getCellStyle().getDataFormatString();
            return new CellDateFormatter(dateFmt).format(date);
        }
        final Double numericCellValue = cell.getNumericCellValue();
        if (isMathematicalInteger(numericCellValue)) {
            return Integer.toString(numericCellValue.intValue());
        }
        return Double.toString(numericCellValue);
    }
    case CELL_TYPE_BLANK:
        return EMPTY_STRING;

    case CELL_TYPE_BOOLEAN:
        return Boolean.toString(cell.getBooleanCellValue());

    case Cell.CELL_TYPE_FORMULA: {
        cell.setCellType(cell.getCachedFormulaResultType());
        return toString();
    }
    case CELL_TYPE_STRING:
        final String stringCellValue = cell.getStringCellValue();
        return quote(stringCellValue);
    case CELL_TYPE_ERROR:
        return FormulaError.forInt(cell.getErrorCellValue()).getString();
    default:
        final CellReference cellReference = new CellReference(cell.getRowIndex(), cell.getColumnIndex());
        throw new ExcelParsingException(
                "Unregistered cell type: " + cellType + " at " + cellReference.formatAsString() + "!",
                new IllegalArgumentException("Not a registered POI cell type: " + cellType));
    }
}