文章18 | 阅读 21375 | 点赞0
导入 jar 包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
相关类与接口
EasyExcel
public class EasyExcel extends EasyExcelFactory {
public EasyExcel() {
}
}
EasyExcelFactory
public class EasyExcelFactory {
************
构造函数
public EasyExcelFactory() {
}
************
write 方法
public static ExcelWriterBuilder write() {
public static ExcelWriterBuilder write(File file) {
public static ExcelWriterBuilder write(File file, Class head) {
public static ExcelWriterBuilder write(String pathName) {
public static ExcelWriterBuilder write(String pathName, Class head) {
public static ExcelWriterBuilder write(OutputStream outputStream) {
public static ExcelWriterBuilder write(OutputStream outputStream, Class head) {
public static ExcelWriterSheetBuilder writerSheet() {
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo) {
public static ExcelWriterSheetBuilder writerSheet(String sheetName) {
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo, String sheetName) {
public static ExcelWriterTableBuilder writerTable() {
public static ExcelWriterTableBuilder writerTable(Integer tableNo) {
//使用table写入
************
read 读取
public static ExcelReaderBuilder read() {
public static ExcelReaderBuilder read(File file) {
public static ExcelReaderBuilder read(File file, ReadListener readListener) {
public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) {
public static ExcelReaderBuilder read(String pathName) {
public static ExcelReaderBuilder read(String pathName, ReadListener readListener) {
public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) {
public static ExcelReaderBuilder read(InputStream inputStream) {
public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) {
public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) {
public static ExcelReaderSheetBuilder readSheet() {
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo) {
public static ExcelReaderSheetBuilder readSheet(String sheetName) {
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo, String sheetName) {
write 操作
ExcelWriterBuilder
public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder<ExcelWriterBuilder, WriteWorkbook> {
private WriteWorkbook writeWorkbook = new WriteWorkbook();
********
构造函数
public ExcelWriterBuilder() {
}
********
普通方法
public ExcelWriterBuilder file(OutputStream outputStream) {
public ExcelWriterBuilder file(File outputFile) {
public ExcelWriterBuilder file(String outputPathName) {
public ExcelWriterBuilder withTemplate(InputStream templateInputStream) {
public ExcelWriterBuilder withTemplate(File templateFile) {
public ExcelWriterBuilder withTemplate(String pathName) {
public ExcelWriterSheetBuilder sheet() {
public ExcelWriterSheetBuilder sheet(Integer sheetNo) {
public ExcelWriterSheetBuilder sheet(String sheetName) {
public ExcelWriterSheetBuilder sheet(Integer sheetNo, String sheetName) {
public ExcelWriterBuilder autoCloseStream(Boolean autoCloseStream) {
public ExcelWriterBuilder password(String password) {
public ExcelWriterBuilder inMemory(Boolean inMemory) {
public ExcelWriterBuilder writeExcelOnException(Boolean writeExcelOnException) {
public ExcelWriterBuilder excelType(ExcelTypeEnum excelType) {
public ExcelWriter build() {
protected WriteWorkbook parameter() {
AbstractExcelWriterParameterBuilder
public abstract class AbstractExcelWriterParameterBuilder<T extends AbstractExcelWriterParameterBuilder, C extends WriteBasicParameter> extends AbstractParameterBuilder<T, C> {
public AbstractExcelWriterParameterBuilder() {
}
public T excludeColumnIndexes(Collection<Integer> excludeColumnIndexes) {
public T excludeColumnFiledNames(Collection<String> excludeColumnFiledNames) {
//不输出的列
public T includeColumnIndexes(Collection<Integer> includeColumnIndexes) {
public T includeColumnFiledNames(Collection<String> includeColumnFiledNames) {
//输出的列
public T relativeHeadRowIndex(Integer relativeHeadRowIndex) {
public T needHead(Boolean needHead) {
public T registerWriteHandler(WriteHandler writeHandler) {
public T useDefaultStyle(Boolean useDefaultStyle) {
public T automaticMergeHead(Boolean automaticMergeHead) {
AbstractParameterBuilder
public abstract class AbstractParameterBuilder<T extends AbstractParameterBuilder, C extends BasicParameter> {
public AbstractParameterBuilder() {
}
public T head(List<List<String>> head) {
public T head(Class clazz) { //设置head
public T registerConverter(Converter converter) { //注册转换器
public T use1904windowing(Boolean use1904windowing) {
public T locale(Locale locale) {
public T autoTrim(Boolean autoTrim) {
protected T self() {
protected abstract C parameter();
ExcelWriterSheetBuilder
public class ExcelWriterSheetBuilder extends AbstractExcelWriterParameterBuilder<ExcelWriterSheetBuilder, WriteSheet> {
private ExcelWriter excelWriter;
private WriteSheet writeSheet = new WriteSheet();
*********
构造函数
public ExcelWriterSheetBuilder() {
public ExcelWriterSheetBuilder(ExcelWriter excelWriter) {
*********
普通方法
public WriteSheet build() {
public void doWrite(List data) {
public void doFill(Object data) {
public void doFill(Object data, FillConfig fillConfig) {
public ExcelWriterSheetBuilder sheetNo(Integer sheetNo) { //写入表单的序列号
public ExcelWriterSheetBuilder sheetName(String sheetName) { //写入表单的名称
public ExcelWriterTableBuilder table() {
public ExcelWriterTableBuilder table(Integer tableNo) {
protected WriteSheet parameter() {
ExcelWriterTableBuilder:使用table写入
public class ExcelWriterTableBuilder extends AbstractExcelWriterParameterBuilder<ExcelWriterTableBuilder, WriteTable> {
private ExcelWriter excelWriter;
private WriteSheet writeSheet;
private WriteTable writeTable;
public ExcelWriterTableBuilder() {
this.writeTable = new WriteTable();
}
public ExcelWriterTableBuilder(ExcelWriter excelWriter, WriteSheet writeSheet) {
this.excelWriter = excelWriter;
this.writeSheet = writeSheet;
this.writeTable = new WriteTable();
}
public ExcelWriterTableBuilder tableNo(Integer tableNo) {
this.writeTable.setTableNo(tableNo);
return this;
}
public WriteTable build() {
return this.writeTable;
}
public void doWrite(List data) {
if (this.excelWriter == null) {
throw new ExcelGenerateException("Must use 'EasyExcelFactory.write().sheet().table()' to call this method");
} else {
this.excelWriter.write(data, this.writeSheet, this.build());
this.excelWriter.finish();
}
}
protected WriteTable parameter() {
return this.writeTable;
}
}
ExcelWriter
public class ExcelWriter {
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelWriter.class);
private ExcelBuilder excelBuilder;
public ExcelWriter(WriteWorkbook writeWorkbook) {
public ExcelWriter write(List data, WriteSheet writeSheet) {
public ExcelWriter write(List data, WriteSheet writeSheet, WriteTable writeTable) {
public ExcelWriter fill(Object data, WriteSheet writeSheet) {
public ExcelWriter fill(Object data, FillConfig fillConfig, WriteSheet writeSheet) {
public void finish() {
public WriteContext writeContext() {
protected void finalize() {
WriteSheet
public class WriteSheet extends WriteBasicParameter {
private Integer sheetNo;
private String sheetName;
public WriteSheet() {
}
public void setSheetNo(Integer sheetNo) {
public void setSheetName(String sheetName) {
public void setColumnWidthMap(Map<Integer, Integer> columnWidthMap) {
public void setTableStyle(TableStyle tableStyle) {
public Integer getSheetNo() {
public String getSheetName() {
public TableStyle getTableStyle() {
public Map<Integer, Integer> getColumnWidthMap() {
public String toString() {
WriteTable
public class WriteTable extends WriteBasicParameter {
private Integer tableNo;
public WriteTable() {
}
public Integer getTableNo() {
return this.tableNo;
}
public void setTableNo(Integer tableNo) {
this.tableNo = tableNo;
}
public TableStyle getTableStyle() {
return this.tableStyle;
}
public void setTableStyle(TableStyle tableStyle) {
this.tableStyle = tableStyle;
}
}
WriteBasicParameter
public class WriteBasicParameter extends BasicParameter {
private Integer relativeHeadRowIndex;
private Boolean needHead;
private List<WriteHandler> customWriteHandlerList = new ArrayList();
private Boolean useDefaultStyle;
private Boolean automaticMergeHead;
private Collection<Integer> excludeColumnIndexes;
private Collection<String> excludeColumnFiledNames;
private Collection<Integer> includeColumnIndexes;
private Collection<String> includeColumnFiledNames;
public WriteBasicParameter() {
}
public void setExcludeColumnIndexes(Collection<Integer> excludeColumnIndexes) {
public void setExcludeColumnFiledNames(Collection<String> excludeColumnFiledNames) {
public Collection<Integer> getExcludeColumnIndexes() {
public Collection<String> getExcludeColumnFiledNames() {
public void setIncludeColumnIndexes(Collection<Integer> includeColumnIndexes) {
public void setIncludeColumnFiledNames(Collection<String> includeColumnFiledNames) {
public Collection<Integer> getIncludeColumnIndexes() {
public Collection<String> getIncludeColumnFiledNames() {
public void setNeedHead(Boolean needHead) {
public void setUseDefaultStyle(Boolean useDefaultStyle) {
public void setAutomaticMergeHead(Boolean automaticMergeHead) {
public void setRelativeHeadRowIndex(Integer relativeHeadRowIndex) {
public void setCustomWriteHandlerList(List<WriteHandler> customWriteHandlerList) {
public Boolean getNeedHead() {
public Boolean getUseDefaultStyle() {
public Boolean getAutomaticMergeHead() {
public Integer getRelativeHeadRowIndex() {
public List<WriteHandler> getCustomWriteHandlerList() {
BasicParameter
public class BasicParameter {
private List<List<String>> head;
private Class clazz;
private List<Converter> customConverterList;
private Boolean autoTrim;
private Boolean use1904windowing;
private Locale locale;
private Boolean useScientificFormat;
public BasicParameter() {
}
public void setClazz(Class clazz) {
public void setHead(List<List<String>> head) {
public Class getClazz() {
public List<List<String>> getHead() {
public List<Converter> getCustomConverterList() {
public void setCustomConverterList(List<Converter> customConverterList) {
public void setLocale(Locale locale) {
public void setAutoTrim(Boolean autoTrim) {
public void setUse1904windowing(Boolean use1904windowing) {
public void setUseScientificFormat(Boolean useScientificFormat) {
public Locale getLocale() {
public Boolean getAutoTrim() {
public Boolean getUse1904windowing() {
public Boolean getUseScientificFormat() {
read 操作
ExcelReaderBuilder
public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<ExcelReaderBuilder, ReadWorkbook> {
private ReadWorkbook readWorkbook = new ReadWorkbook();
public ExcelReaderBuilder() {
}
public ExcelReaderBuilder file(InputStream inputStream) {
public ExcelReaderBuilder file(File file) {
public ExcelReaderBuilder file(String pathName) {
public ExcelReaderSheetBuilder sheet() {
public ExcelReaderSheetBuilder sheet(Integer sheetNo) {
public ExcelReaderSheetBuilder sheet(String sheetName) {
public ExcelReaderSheetBuilder sheet(Integer sheetNo, String sheetName) {
public void doReadAll() {
public <T> List<T> doReadAllSync() {
public ExcelReaderBuilder excelType(ExcelTypeEnum excelType) {
public ExcelReaderBuilder mandatoryUseInputStream(Boolean mandatoryUseInputStream) {
public ExcelReaderBuilder autoCloseStream(Boolean autoCloseStream) {
public ExcelReaderBuilder ignoreEmptyRow(Boolean ignoreEmptyRow) {
public ExcelReaderBuilder customObject(Object customObject) {
public ExcelReaderBuilder readCache(ReadCache readCache) {
public ExcelReaderBuilder readCacheSelector(ReadCacheSelector readCacheSelector) {
public ExcelReaderBuilder password(String password) {
public ExcelReaderBuilder xlsxSAXParserFactoryName(String xlsxSAXParserFactoryName) {
public ExcelReaderBuilder extraRead(CellExtraTypeEnum extraType) {
public ExcelReaderBuilder useDefaultListener(Boolean useDefaultListener) {
public ExcelReader build() {
protected ReadWorkbook parameter() {
ExcelReaderSheetBuilder
public class ExcelReaderSheetBuilder extends AbstractExcelReaderParameterBuilder<ExcelReaderSheetBuilder, ReadSheet> {
private ExcelReader excelReader;
private ReadSheet readSheet = new ReadSheet();
public ExcelReaderSheetBuilder() {
public ExcelReaderSheetBuilder(ExcelReader excelReader) {
public ExcelReaderSheetBuilder sheetNo(Integer sheetNo) {
public ExcelReaderSheetBuilder sheetName(String sheetName) {
public ReadSheet build() {
public void doRead() {
public <T> List<T> doReadSync() {
protected ReadSheet parameter() {
AbstractExcelReaderParameterBuilder
public abstract class AbstractExcelReaderParameterBuilder<T extends AbstractExcelReaderParameterBuilder, C extends ReadBasicParameter> extends AbstractParameterBuilder<T, C> {
public AbstractExcelReaderParameterBuilder() {
}
public T headRowNumber(Integer headRowNumber) {
public T useScientificFormat(Boolean useScientificFormat) {
public T registerReadListener(ReadListener readListener) {
AnalysisEventListener:监听器
public abstract class AnalysisEventListener<T> implements ReadListener<T> {
public AnalysisEventListener() {
}
public void invokeHead(Map<Integer, CellData> headMap, AnalysisContext context) {
this.invokeHeadMap(ConverterUtils.convertToStringMap(headMap, context), context);
}
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
}
public void extra(CellExtra extra, AnalysisContext context) {
}
public void onException(Exception exception, AnalysisContext context) throws Exception {
throw exception;
}
public boolean hasNext(AnalysisContext context) {
return true;
}
}
ReadListener
public interface ReadListener<T> extends Listener {
void invoke(T var1, AnalysisContext var2);
void invokeHead(Map<Integer, CellData> var1, AnalysisContext var2);
boolean hasNext(AnalysisContext var1);
void doAfterAllAnalysed(AnalysisContext var1);
void extra(CellExtra var1, AnalysisContext var2);
void onException(Exception var1, AnalysisContext var2) throws Exception;
}
Listener
public interface Listener {
}
ExcelReader
public class ExcelReader {
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelReader.class);
private ExcelAnalyser excelAnalyser;
public ExcelReader(ReadWorkbook readWorkbook) {
public void readAll() {
public ExcelReader read(ReadSheet... readSheet) {
public ExcelReader read(List<ReadSheet> readSheetList) {
public AnalysisContext analysisContext() {
public ExcelReadExecutor excelExecutor() {
public void finish() {
protected void finalize() {
ReadSheet
public class ReadSheet extends ReadBasicParameter {
private Integer sheetNo;
private String sheetName;
public ReadSheet() {
public ReadSheet(Integer sheetNo) {
public ReadSheet(Integer sheetNo, String sheetName) {
public void setSheetNo(Integer sheetNo) {
public void setSheetName(String sheetName) {
public Integer getSheetNo() {
public String getSheetName() {
public void copyBasicParameter(ReadSheet other) {
public String toString() {
ReadBasicParameter
public class ReadBasicParameter extends BasicParameter {
private Integer headRowNumber;
private List<ReadListener> customReadListenerList = new ArrayList();
public ReadBasicParameter() {
}
public void setHeadRowNumber(Integer headRowNumber) {
public void setCustomReadListenerList(List<ReadListener> customReadListenerList) {
public Integer getHeadRowNumber() {
public List<ReadListener> getCustomReadListenerList() {
相关注解
format
@DateTimeFormat:标注在字段上,日期格式化
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface DateTimeFormat {
String value() default "";
boolean use1904windowing() default false;
}
@NumberFormat:标注在字段上,数字格式化
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface NumberFormat {
String value() default "";
RoundingMode roundingMode() default RoundingMode.HALF_UP;
}
write.style:输出样式注解
ColumnWidth:标注在类、字段上,设置列宽
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ColumnWidth {
int value() default -1;
}
HeadRowHeight:标注在类上,设置表头高度
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadRowHeight {
short value() default -1;
}
ContentRowHeight:标注在类上,设置内容列表高度
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ContentRowHeight {
short value() default -1;
}
其余注解
ExcelIgnore:标注在字段上,不输出
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelIgnore {
}
ExcelIgnoreUnannotated:标注在类上,忽略没有注释的字段
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelIgnoreUnannotated {
}
ExcelProperty:标注在字段上,设置顺序,名称,列索引
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelProperty {
String[] value() default {""};
int index() default -1;
int order() default 2147483647;
Class<? extends Converter> converter() default AutoConverter.class;
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_43931625/article/details/107516482
内容来源于网络,如有侵权,请联系作者删除!