-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
166 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/pig4cloud/plugin/excel/converters/LocalTimeStringConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.pig4cloud.plugin.excel.converters; | ||
|
||
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 java.text.ParseException; | ||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* LocalDate and string converter | ||
* | ||
* @author L.cm | ||
*/ | ||
public enum LocalTimeStringConverter implements Converter<LocalTime> { | ||
|
||
/** | ||
* 实例 | ||
*/ | ||
INSTANCE; | ||
|
||
@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 LocalTime.parse(cellData.getStringValue()); | ||
} | ||
else { | ||
DateTimeFormatter formatter = DateTimeFormatter | ||
.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat()); | ||
return LocalTime.parse(cellData.getStringValue(), formatter); | ||
} | ||
} | ||
|
||
@Override | ||
public WriteCellData<String> convertToExcelData(LocalTime value, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) { | ||
DateTimeFormatter formatter; | ||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { | ||
formatter = DateTimeFormatter.ISO_LOCAL_TIME; | ||
} | ||
else { | ||
formatter = DateTimeFormatter.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat()); | ||
} | ||
return new WriteCellData<>(value.format(formatter)); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/pig4cloud/plugin/excel/converters/LongStringConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.pig4cloud.plugin.excel.converters; | ||
|
||
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 java.text.ParseException; | ||
|
||
/** | ||
* Long and string converter | ||
* | ||
* @author L.cm | ||
*/ | ||
public enum LongStringConverter implements Converter<Long> { | ||
|
||
/** | ||
* 实例 | ||
*/ | ||
INSTANCE; | ||
|
||
@Override | ||
public Class supportJavaTypeKey() { | ||
return Long.class; | ||
} | ||
|
||
@Override | ||
public CellDataTypeEnum supportExcelTypeKey() { | ||
return CellDataTypeEnum.STRING; | ||
} | ||
|
||
@Override | ||
public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) throws ParseException { | ||
return Long.parseLong(cellData.getStringValue()); | ||
} | ||
|
||
@Override | ||
public WriteCellData<String> convertToExcelData(Long value, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) { | ||
return new WriteCellData<>(String.valueOf(value)); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/pig4cloud/plugin/excel/converters/StringArrayConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.pig4cloud.plugin.excel.converters; | ||
|
||
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 java.text.ParseException; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* LocalDate and string converter | ||
* | ||
* @author L.cm | ||
*/ | ||
public enum StringArrayConverter implements Converter<String[]> { | ||
|
||
/** | ||
* 实例 | ||
*/ | ||
INSTANCE; | ||
|
||
@Override | ||
public Class supportJavaTypeKey() { | ||
return String[].class; | ||
} | ||
|
||
@Override | ||
public CellDataTypeEnum supportExcelTypeKey() { | ||
return CellDataTypeEnum.STRING; | ||
} | ||
|
||
@Override | ||
public String[] convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) throws ParseException { | ||
return cellData.getStringValue().split(","); | ||
} | ||
|
||
@Override | ||
public WriteCellData<String> convertToExcelData(String[] value, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) { | ||
return new WriteCellData<>(Arrays.stream(value).collect(Collectors.joining())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters