Skip to content

Commit

Permalink
🔖 Releasing / Version tags. 3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Apr 6, 2024
1 parent 1d17141 commit c93c44c
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目

| 版本 | 支持 |
|-------|--|
| 3.2.0 | 适配 SpringBoot3.x |
| 3.2.1 | 适配 SpringBoot3.x |
| 1.2.7 | 适配 SpringBoot2.x |

```xml
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.pig4cloud.excel</groupId>
<artifactId>excel-spring-boot-starter</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<name>excel-spring-boot-starter</name>
<description>easy and high performance excel</description>
<url>https://pig4cloud.com</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.alibaba.excel.EasyExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.converters.LocalDateStringConverter;
import com.pig4cloud.plugin.excel.converters.LocalDateTimeStringConverter;
import com.pig4cloud.plugin.excel.converters.*;
import com.pig4cloud.plugin.excel.handler.ListAnalysisEventListener;
import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -74,6 +73,9 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
EasyExcel.read(inputStream, excelModelClass, readListener)
.registerConverter(LocalDateStringConverter.INSTANCE)
.registerConverter(LocalDateTimeStringConverter.INSTANCE)
.registerConverter(LocalTimeStringConverter.INSTANCE)
.registerConverter(LongStringConverter.INSTANCE)
.registerConverter(StringArrayConverter.INSTANCE)
.ignoreEmptyRow(requestExcel.ignoreEmptyRow())
.sheet()
.headRowNumber(requestExcel.headRowNumber())
Expand Down
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));
}

}
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));
}

}
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()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import com.pig4cloud.plugin.excel.annotation.Sheet;
import com.pig4cloud.plugin.excel.aop.DynamicNameAspect;
import com.pig4cloud.plugin.excel.config.ExcelConfigProperties;
import com.pig4cloud.plugin.excel.converters.LocalDateStringConverter;
import com.pig4cloud.plugin.excel.converters.LocalDateTimeStringConverter;
import com.pig4cloud.plugin.excel.converters.*;
import com.pig4cloud.plugin.excel.enhance.WriterBuilderEnhancer;
import com.pig4cloud.plugin.excel.head.HeadGenerator;
import com.pig4cloud.plugin.excel.head.HeadMeta;
Expand Down Expand Up @@ -110,6 +109,9 @@ public ExcelWriter getExcelWriter(HttpServletResponse response, ResponseExcel re
ExcelWriterBuilder writerBuilder = EasyExcel.write(response.getOutputStream())
.registerConverter(LocalDateStringConverter.INSTANCE)
.registerConverter(LocalDateTimeStringConverter.INSTANCE)
.registerConverter(LocalTimeStringConverter.INSTANCE)
.registerConverter(LongStringConverter.INSTANCE)
.registerConverter(StringArrayConverter.INSTANCE)
.autoCloseStream(true)
.excelType(responseExcel.suffix())
.inMemory(responseExcel.inMemory());
Expand Down

0 comments on commit c93c44c

Please sign in to comment.