mirror of https://github.com/alibaba/easyexcel
8 changed files with 122 additions and 4 deletions
@ -0,0 +1,52 @@ |
|||||||
|
package com.alibaba.excel.converters.localtime; |
||||||
|
|
||||||
|
import com.alibaba.excel.converters.Converter; |
||||||
|
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||||
|
import com.alibaba.excel.metadata.GlobalConfiguration; |
||||||
|
import com.alibaba.excel.metadata.data.ReadCellData; |
||||||
|
import com.alibaba.excel.metadata.data.WriteCellData; |
||||||
|
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||||
|
import com.alibaba.excel.util.DateUtils; |
||||||
|
|
||||||
|
import java.text.ParseException; |
||||||
|
import java.time.LocalTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* LocalTime and string converter |
||||||
|
* |
||||||
|
* @author yuhaowin |
||||||
|
*/ |
||||||
|
public class LocalTimeStringConverter implements Converter<LocalTime> { |
||||||
|
@Override |
||||||
|
public Class<?> supportJavaTypeKey() { |
||||||
|
return LocalTime.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CellDataTypeEnum supportExcelTypeKey() { |
||||||
|
return CellDataTypeEnum.STRING; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public LocalTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, |
||||||
|
GlobalConfiguration globalConfiguration) throws ParseException { |
||||||
|
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||||
|
return DateUtils.parseLocalTime(cellData.getStringValue(), null, globalConfiguration.getLocale()); |
||||||
|
} else { |
||||||
|
return DateUtils.parseLocalTime(cellData.getStringValue(), |
||||||
|
contentProperty.getDateTimeFormatProperty().getFormat(), globalConfiguration.getLocale()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public WriteCellData<?> convertToExcelData(LocalTime value, ExcelContentProperty contentProperty, |
||||||
|
GlobalConfiguration globalConfiguration) { |
||||||
|
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { |
||||||
|
return new WriteCellData<>(DateUtils.format(value, null, globalConfiguration.getLocale())); |
||||||
|
} else { |
||||||
|
return new WriteCellData<>( |
||||||
|
DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat(), |
||||||
|
globalConfiguration.getLocale())); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue