forked from fanruan/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
package com.alibaba.excel.converters.date; |
|
|
|
import java.util.Date; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
|
|
|
import com.alibaba.excel.converters.Converter; |
|
import com.alibaba.excel.enums.CellDataTypeEnum; |
|
import com.alibaba.excel.metadata.CellData; |
|
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
|
|
|
/** |
|
* Date and number converter |
|
* |
|
* @author zhuangjiaju |
|
*/ |
|
public class DateNumberConverter implements Converter<Date> { |
|
|
|
@Override |
|
public Class supportJavaTypeKey() { |
|
return Date.class; |
|
} |
|
|
|
@Override |
|
public CellDataTypeEnum supportExcelTypeKey() { |
|
return CellDataTypeEnum.NUMBER; |
|
} |
|
|
|
@Override |
|
public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty) { |
|
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
|
Boolean use1904windowing = Boolean.FALSE; |
|
if (contentProperty != null && contentProperty.getUse1904windowing() != null) { |
|
use1904windowing = contentProperty.getUse1904windowing(); |
|
} |
|
return HSSFDateUtil.getJavaDate(cellData.getDoubleValue(), use1904windowing, null); |
|
} else { |
|
return HSSFDateUtil.getJavaDate(cellData.getDoubleValue(), |
|
contentProperty.getDateTimeFormatProperty().getUse1904windowing(), null); |
|
} |
|
} |
|
|
|
@Override |
|
public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty) { |
|
return new CellData((double)(value.getTime())); |
|
} |
|
}
|
|
|