Skip to content

Commit

Permalink
Merge pull request #231 from shiyindaxiaojie/feature
Browse files Browse the repository at this point in the history
update
  • Loading branch information
shiyindaxiaojie authored Feb 20, 2025
2 parents 9037391 + f72c8e0 commit 69b583c
Show file tree
Hide file tree
Showing 16 changed files with 659 additions and 2 deletions.
7 changes: 7 additions & 0 deletions eden-components/eden-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<jakarta.el.version>3.0.4</jakarta.el.version>
<classmate.version>1.5.1</classmate.version>
<easyexcel.version>3.2.0</easyexcel.version>
<fastexcel.version>1.1.0</fastexcel.version>
<poi.version>4.1.1</poi.version>
<dom4j.version>2.1.3</dom4j.version>
<batik.version>1.12</batik.version>
Expand Down Expand Up @@ -1134,6 +1135,12 @@
<version>${jakarta.el.version}</version>
</dependency>
<!-- EasyExcel -->
<dependency>
<groupId>cn.idev.excel</groupId>
<artifactId>fastexcel</artifactId>
<version>${fastexcel.version}</version>
</dependency>
<!-- FastExcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions eden-components/eden-solutions/eden-common-excel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@
<optional>true</optional>
</dependency>

<!-- EasyExcel -->
<dependency>
<groupId>cn.idev.excel</groupId>
<artifactId>fastexcel</artifactId>
</dependency>

<!-- EasyExcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<optional>true</optional>
</dependency>

<!-- Other -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ylzl.eden.common.excel;

import java.lang.annotation.*;

/**
* Excel 属性项
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.x
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelProperty {

String[] value() default {""};

int index() default -1;

int order() default Integer.MAX_VALUE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ylzl.eden.common.excel.converter;

/**
* TODO
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.x
*/
public interface Converter<T> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ylzl.eden.common.excel.integration.fastexcel;

import cn.idev.excel.context.AnalysisContext;
import cn.idev.excel.event.AnalysisEventListener;
import cn.idev.excel.read.builder.ExcelReaderBuilder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.ylzl.eden.common.excel.ExcelReader;
import org.ylzl.eden.common.excel.reader.ExcelReadListener;

import java.io.File;
import java.io.InputStream;

/**
* EasyExcel 读取 Excel
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.x
*/
@RequiredArgsConstructor
@Data
public class FastExcelReader implements ExcelReader {

private final ExcelReaderBuilder excelReaderBuilder;

private boolean readExcelLine = false;

/**
* 读取 Excel
*
* @param inputStream 输入流
* @param head 标题映射
* @param excelReadListener 读取监听器
*/
@Override
public void read(InputStream inputStream, Class<?> head, ExcelReadListener<?> excelReadListener) {
excelReaderBuilder.file(inputStream)
.head(head)
.autoCloseStream(true)
.registerReadListener(new AnalysisEventListener<Object>() {

@Override
public void invoke(Object data, AnalysisContext context) {
excelReadListener.read(data);
}

@Override
public void doAfterAllAnalysed(AnalysisContext context) {
excelReadListener.finish();
}
})
.sheet()
.doRead();
}

/**
* 读取 Excel
*
* @param file 文件
* @param head 标题映射
* @param excelReadListener 读取监听器
*/
@Override
public void read(File file, Class<?> head, ExcelReadListener<?> excelReadListener) {
excelReaderBuilder.file(file)
.head(head)
.registerReadListener(new AnalysisEventListener<Object>() {

@Override
public void invoke(Object data, AnalysisContext context) {
excelReadListener.read(data);
}

@Override
public void doAfterAllAnalysed(AnalysisContext context) {
excelReadListener.finish();
}
})
.sheet()
.doRead();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ylzl.eden.common.excel.integration.fastexcel;

import cn.idev.excel.FastExcel;
import org.ylzl.eden.common.excel.ExcelReader;
import org.ylzl.eden.common.excel.builder.AbstractExcelReaderBuilder;
import org.ylzl.eden.common.excel.builder.ExcelReaderBuilder;
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateConverter;
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateTimeConverter;

/**
* EasyExcel 读取 Excel
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.x
*/
public class FastExcelReaderBuilder extends AbstractExcelReaderBuilder implements ExcelReaderBuilder {

/**
* 构建 Excel 读取器
*
* @param headRowNumber 标题行数
* @param ignoreEmptyRow 忽略空行
* @return Excel 读取器实例
*/
@Override
public ExcelReader build(int headRowNumber, boolean ignoreEmptyRow) {
return new FastExcelReader(FastExcel.read()
.registerConverter(LocalDateConverter.INSTANCE)
.registerConverter(LocalDateTimeConverter.INSTANCE)
.headRowNumber(headRowNumber)
.ignoreEmptyRow(ignoreEmptyRow));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.ylzl.eden.common.excel.integration.fastexcel;

import cn.idev.excel.write.builder.ExcelWriterBuilder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.ylzl.eden.common.excel.ExcelWriter;

import java.io.File;
import java.io.OutputStream;
import java.util.List;

/**
* EasyExcel 写入 Excel
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.13
*/
@RequiredArgsConstructor
@Data
public class FastExcelWriter implements ExcelWriter {

private final ExcelWriterBuilder excelWriterBuilder;

/**
* 写入 Excel
*
* @param outputStream 输出流
* @param data 填充数据
* @param head 标题
*/
@Override
public void write(OutputStream outputStream, List<Object> data, Class<?> head) {
excelWriterBuilder.file(outputStream)
.autoCloseStream(true)
.head(head)
.sheet()
.doWrite(data);
}

/**
* 写入 Excel
*
* @param file 文件
* @param data 填充数据
* @param head 标题
*/
@Override
public void write(File file, List<Object> data, Class<?> head) {
excelWriterBuilder.file(file)
.autoCloseStream(true)
.head(head)
.sheet()
.doWrite(data);
}

private cn.idev.excel.ExcelWriter build(OutputStream outputStream) {
return excelWriterBuilder.file(outputStream)
.autoCloseStream(true)
.build();
}

private boolean isManySheets(Object data) {
if (data instanceof List) {
List<?> objList = (List<?>) data;
return !objList.isEmpty() && objList.get(0) instanceof List;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ylzl.eden.common.excel.integration.fastexcel;

import cn.idev.excel.FastExcel;
import cn.idev.excel.support.ExcelTypeEnum;
import org.ylzl.eden.common.excel.ExcelType;
import org.ylzl.eden.common.excel.ExcelWriter;
import org.ylzl.eden.common.excel.builder.AbstractExcelWriterBuilder;
import org.ylzl.eden.common.excel.builder.ExcelWriterBuilder;
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateConverter;
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateTimeConverter;

/**
* EasyExcel 写入 Excel
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.x
*/
public class FastExcelWriterBuilder extends AbstractExcelWriterBuilder implements ExcelWriterBuilder {

/**
* 构建 Excel 写入器
*
* @param excelType 文件类型
* @param inMemory 是否在内存操作
* @return Excel 写入器实例
*/
@Override
public ExcelWriter build(ExcelType excelType, boolean inMemory) {
return new FastExcelWriter(FastExcel.write()
.registerConverter(LocalDateConverter.INSTANCE)
.registerConverter(LocalDateTimeConverter.INSTANCE)
.excelType(this.valueOf(excelType))
.inMemory(inMemory));
}

/**
* 枚举转换
*
* @param excelType 文件类型
* @return EasyExcel 枚举
*/
private ExcelTypeEnum valueOf(ExcelType excelType) {
switch (excelType) {
case CSV:
return ExcelTypeEnum.CSV;
case XLS:
return ExcelTypeEnum.XLS;
}
return ExcelTypeEnum.XLSX;
}
}
Loading

0 comments on commit 69b583c

Please sign in to comment.