lead
6 天以前 bc00242ee0410684eb9f4c5fe0aa486dfebb3162
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cn.iocoder.yudao.framework.excel.core.convert;
 
import cn.idev.excel.converters.Converter;
import cn.idev.excel.enums.CellDataTypeEnum;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;
 
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
 
/**
 * Excel LocalTime 转换器
 *
 * FastExcel 内置只支持 Date / LocalDateTime,遇到 LocalTime 字段会抛
 * {@code ExcelWriteDataConvertException: Can not find 'Converter' support class LocalTime},
 * 因此这里补一个转换器,供班次、考勤规则等含时间字段的 VO 导出时使用。
 *
 * @author 超级管理员
 */
public class LocalTimeConvert implements Converter<LocalTime> {
 
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
 
    @Override
    public Class<?> supportJavaTypeKey() {
        throw new UnsupportedOperationException("暂不支持,也不需要");
    }
 
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        throw new UnsupportedOperationException("暂不支持,也不需要");
    }
 
    @Override
    public WriteCellData<String> convertToExcelData(LocalTime value, ExcelContentProperty contentProperty,
                                                    GlobalConfiguration globalConfiguration) {
        if (value == null) {
            return new WriteCellData<>("");
        }
        return new WriteCellData<>(value.format(FORMATTER));
    }
 
}