| New file |
| | |
| | | package org.sxkj.fw.utils.excel; |
| | | |
| | | import com.alibaba.excel.converters.Converter; |
| | | import com.alibaba.excel.converters.WriteConverterContext; |
| | | 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 java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | |
| | | /** |
| | | * LocalTime转换器 |
| | | * |
| | | * @author |
| | | * @since 2026-01-09 |
| | | */ |
| | | public class LocalTimeConverter implements Converter<LocalTime> { |
| | | |
| | | private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | | |
| | | @Override |
| | | public Class<LocalTime> supportJavaTypeKey() { |
| | | return LocalTime.class; |
| | | } |
| | | |
| | | @Override |
| | | public CellDataTypeEnum supportExcelTypeKey() { |
| | | return CellDataTypeEnum.STRING; |
| | | } |
| | | |
| | | @Override |
| | | public LocalTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | if (cellData == null || cellData.getStringValue() == null || cellData.getStringValue().trim().isEmpty()) { |
| | | return null; |
| | | } |
| | | try { |
| | | return LocalTime.parse(cellData.getStringValue(), TIME_FORMATTER); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public WriteCellData<?> convertToExcelData(WriteConverterContext<LocalTime> context) throws Exception { |
| | | if (context.getValue() == null) { |
| | | return new WriteCellData<>(""); |
| | | } |
| | | return new WriteCellData<>(context.getValue().format(TIME_FORMATTER)); |
| | | } |
| | | } |