✨ excel导出支持自定义头信息
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.hccake.common.excel;
|
||||
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.hccake.common.excel.config.ExcelConfigProperties;
|
||||
import com.hccake.common.excel.handler.ManySheetWriteHandler;
|
||||
import com.hccake.common.excel.handler.SingleSheetWriteHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Hccake 2020/10/28
|
||||
* @version 1.0
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class SheetWriteHandlerAutoConfiguration {
|
||||
|
||||
private final ExcelConfigProperties configProperties;
|
||||
|
||||
private final ObjectProvider<List<Converter<?>>> converterProvider;
|
||||
|
||||
/**
|
||||
* 单sheet 写入处理器
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SingleSheetWriteHandler singleSheetWriteHandler() {
|
||||
return new SingleSheetWriteHandler(configProperties, converterProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多sheet 写入处理器
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ManySheetWriteHandler manySheetWriteHandler() {
|
||||
return new ManySheetWriteHandler(configProperties, converterProvider);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.hccake.common.excel.head;
|
||||
|
||||
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Excel头生成器,用于自定义生成头部信息
|
||||
*
|
||||
* @author Hccake 2020/10/27
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface HeadGenerator {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自定义头部信息
|
||||
* </p>
|
||||
* 实现类根据数据的class信息,定制Excel头<br/>
|
||||
* 具体方法使用参考:https://www.yuque.com/easyexcel/doc/write#b4b9de00
|
||||
* @param writerBuilder ExcelWriterBuilder
|
||||
* @param clazz 当前sheet的数据类型
|
||||
* @return List<List<String>> Head头信息
|
||||
*/
|
||||
List<List<String>> head(ExcelWriterBuilder writerBuilder, Class<?> clazz);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user