Java Code Examples for com.alibaba.excel.metadata.property.ExcelContentProperty#getDateTimeFormatProperty()

The following examples show how to use com.alibaba.excel.metadata.property.ExcelContentProperty#getDateTimeFormatProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringNumberConverter.java    From easyexcel with Apache License 2.0 6 votes vote down vote up
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
    GlobalConfiguration globalConfiguration) {
    // If there are "DateTimeFormat", read as date
    if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) {
        return DateUtils.format(
            DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
                contentProperty.getDateTimeFormatProperty().getUse1904windowing(), null),
            contentProperty.getDateTimeFormatProperty().getFormat());
    }
    // If there are "NumberFormat", read as number
    if (contentProperty != null && contentProperty.getNumberFormatProperty() != null) {
        return NumberUtils.format(cellData.getNumberValue(), contentProperty);
    }
    // Excel defines formatting
    if (cellData.getDataFormat() != null && !StringUtils.isEmpty(cellData.getDataFormatString())) {
        return NumberDataFormatterUtils.format(cellData.getNumberValue().doubleValue(), cellData.getDataFormat(),
            cellData.getDataFormatString(), globalConfiguration);
    }
    // Default conversion number
    return NumberUtils.format(cellData.getNumberValue(), contentProperty);
}
 
Example 2
Source File: DateStringConverter.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
    GlobalConfiguration globalConfiguration) throws ParseException {
    if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
        return DateUtils.parseDate(cellData.getStringValue(), null);
    } else {
        return DateUtils.parseDate(cellData.getStringValue(),
            contentProperty.getDateTimeFormatProperty().getFormat());
    }
}
 
Example 3
Source File: DateStringConverter.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
    GlobalConfiguration globalConfiguration) {
    if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
        return new CellData(DateUtils.format(value, null));
    } else {
        return new CellData(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat()));
    }
}
 
Example 4
Source File: DateNumberConverter.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
    GlobalConfiguration globalConfiguration) {
    if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
        return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
            globalConfiguration.getUse1904windowing(), null);
    } else {
        return DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(),
            contentProperty.getDateTimeFormatProperty().getUse1904windowing(), null);
    }
}
 
Example 5
Source File: DateNumberConverter.java    From easyexcel with Apache License 2.0 5 votes vote down vote up
@Override
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty,
    GlobalConfiguration globalConfiguration) {
    if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
        return new CellData(
            BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing())));
    } else {
        return new CellData(BigDecimal.valueOf(
            DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing())));
    }
}