forked from alibaba/easyexcel
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7fac3bf
commit 6ff6fbf
Showing
15 changed files
with
297 additions
and
21 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
36 changes: 36 additions & 0 deletions
36
...cel-core/src/main/java/com/alibaba/excel/converters/localdate/LocalDateDateConverter.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,36 @@ | ||
package com.alibaba.excel.converters.localdate; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
import com.alibaba.excel.converters.Converter; | ||
import com.alibaba.excel.metadata.GlobalConfiguration; | ||
import com.alibaba.excel.metadata.data.WriteCellData; | ||
import com.alibaba.excel.metadata.property.ExcelContentProperty; | ||
import com.alibaba.excel.util.DateUtils; | ||
import com.alibaba.excel.util.WorkBookUtil; | ||
|
||
/** | ||
* LocalDate and date converter | ||
* | ||
* @author Jiaju Zhuang | ||
*/ | ||
public class LocalDateDateConverter implements Converter<LocalDate> { | ||
@Override | ||
public Class<?> supportJavaTypeKey() { | ||
return LocalDate.class; | ||
} | ||
|
||
@Override | ||
public WriteCellData<?> convertToExcelData(LocalDate value, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) throws Exception { | ||
LocalDateTime localDateTime = value == null ? null : value.atTime(0, 0); | ||
WriteCellData<?> cellData = new WriteCellData<>(localDateTime); | ||
String format = null; | ||
if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) { | ||
format = contentProperty.getDateTimeFormatProperty().getFormat(); | ||
} | ||
WorkBookUtil.fillDataFormat(cellData, format, DateUtils.defaultLocalDateFormat); | ||
return cellData; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...l-core/src/main/java/com/alibaba/excel/converters/localdate/LocalDateStringConverter.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,52 @@ | ||
package com.alibaba.excel.converters.localdate; | ||
|
||
import java.text.ParseException; | ||
import java.time.LocalDate; | ||
|
||
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; | ||
|
||
/** | ||
* LocalDate and string converter | ||
* | ||
* @author Jiaju Zhuang | ||
*/ | ||
public class LocalDateStringConverter implements Converter<LocalDate> { | ||
@Override | ||
public Class<?> supportJavaTypeKey() { | ||
return LocalDate.class; | ||
} | ||
|
||
@Override | ||
public CellDataTypeEnum supportExcelTypeKey() { | ||
return CellDataTypeEnum.STRING; | ||
} | ||
|
||
@Override | ||
public LocalDate convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) throws ParseException { | ||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { | ||
return DateUtils.parseLocalDate(cellData.getStringValue(), null, globalConfiguration.getLocale()); | ||
} else { | ||
return DateUtils.parseLocalDate(cellData.getStringValue(), | ||
contentProperty.getDateTimeFormatProperty().getFormat(), globalConfiguration.getLocale()); | ||
} | ||
} | ||
|
||
@Override | ||
public WriteCellData<?> convertToExcelData(LocalDate 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())); | ||
} | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...rc/main/java/com/alibaba/excel/converters/localdatetime/LocalDateTimeNumberConverter.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,56 @@ | ||
package com.alibaba.excel.converters.localdatetime; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDateTime; | ||
|
||
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 org.apache.poi.ss.usermodel.DateUtil; | ||
|
||
/** | ||
* LocalDateTime and number converter | ||
* | ||
* @author Jiaju Zhuang | ||
*/ | ||
public class LocalDateTimeNumberConverter implements Converter<LocalDateTime> { | ||
|
||
@Override | ||
public Class<?> supportJavaTypeKey() { | ||
return LocalDateTime.class; | ||
} | ||
|
||
@Override | ||
public CellDataTypeEnum supportExcelTypeKey() { | ||
return CellDataTypeEnum.NUMBER; | ||
} | ||
|
||
@Override | ||
public LocalDateTime convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) { | ||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { | ||
return DateUtils.getLocalDateTime(cellData.getNumberValue().doubleValue(), | ||
globalConfiguration.getUse1904windowing()); | ||
} else { | ||
return DateUtils.getLocalDateTime(cellData.getNumberValue().doubleValue(), | ||
contentProperty.getDateTimeFormatProperty().getUse1904windowing()); | ||
} | ||
} | ||
|
||
@Override | ||
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, | ||
GlobalConfiguration globalConfiguration) { | ||
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { | ||
return new WriteCellData<>( | ||
BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); | ||
} else { | ||
return new WriteCellData<>(BigDecimal.valueOf( | ||
DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.