-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from shiyindaxiaojie/feature
update
- Loading branch information
Showing
16 changed files
with
659 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
...n-solutions/eden-common-excel/src/main/java/org/ylzl/eden/common/excel/ExcelProperty.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,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; | ||
} |
27 changes: 27 additions & 0 deletions
27
...tions/eden-common-excel/src/main/java/org/ylzl/eden/common/excel/converter/Converter.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,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> { | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...excel/src/main/java/org/ylzl/eden/common/excel/integration/fastexcel/FastExcelReader.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,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(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...rc/main/java/org/ylzl/eden/common/excel/integration/fastexcel/FastExcelReaderBuilder.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,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)); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...excel/src/main/java/org/ylzl/eden/common/excel/integration/fastexcel/FastExcelWriter.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,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; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...rc/main/java/org/ylzl/eden/common/excel/integration/fastexcel/FastExcelWriterBuilder.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,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; | ||
} | ||
} |
Oops, something went wrong.