Skip to content

Commit

Permalink
⬆️ Upgrading dependencies. easyexcel 1.2.6 fix 多sheet 空数据数组越界问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lbw committed Sep 20, 2022
1 parent cf20a23 commit 831275d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目
<dependency>
<groupId>com.pig4cloud.excel</groupId>
<artifactId>excel-spring-boot-starter</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
</dependency>
```

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>1.2.5</version>
<version>1.2.6</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 @@ -115,11 +115,11 @@ public ExcelWriter getExcelWriter(HttpServletResponse response, ResponseExcel re
}

if (responseExcel.include().length != 0) {
writerBuilder.includeColumnFiledNames(Arrays.asList(responseExcel.include()));
writerBuilder.includeColumnFieldNames(Arrays.asList(responseExcel.include()));
}

if (responseExcel.exclude().length != 0) {
writerBuilder.excludeColumnFiledNames(Arrays.asList(responseExcel.exclude()));
writerBuilder.excludeColumnFieldNames(Arrays.asList(responseExcel.exclude()));
}

if (responseExcel.writeHandler().length != 0) {
Expand Down Expand Up @@ -197,10 +197,10 @@ else if (isNotInterface(bookHeadEnhancerClass)) {
else if (dataClass != null) {
writerSheetBuilder.head(dataClass);
if (sheet.excludes().length > 0) {
writerSheetBuilder.excludeColumnFiledNames(Arrays.asList(sheet.excludes()));
writerSheetBuilder.excludeColumnFieldNames(Arrays.asList(sheet.excludes()));
}
if (sheet.includes().length > 0) {
writerSheetBuilder.includeColumnFiledNames(Arrays.asList(sheet.includes()));
writerSheetBuilder.includeColumnFieldNames(Arrays.asList(sheet.includes()));
}
}

Expand All @@ -217,7 +217,7 @@ private void fillCustomHeadInfo(Class<?> dataClass, Class<? extends HeadGenerato
Assert.notNull(headGenerator, "The header generated bean does not exist.");
HeadMeta head = headGenerator.head(dataClass);
writerSheetBuilder.head(head.getHead());
writerSheetBuilder.excludeColumnFiledNames(head.getIgnoreHeadFields());
writerSheetBuilder.excludeColumnFieldNames(head.getIgnoreHeadFields());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pig4cloud.plugin.excel.handler;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.write.metadata.WriteSheet;
Expand All @@ -9,6 +10,7 @@
import com.pig4cloud.plugin.excel.enhance.WriterBuilderEnhancer;
import com.pig4cloud.plugin.excel.kit.ExcelException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
Expand Down Expand Up @@ -50,9 +52,17 @@ public void write(Object obj, HttpServletResponse response, ResponseExcel respon
WriteSheet sheet;
for (int i = 0; i < sheets.length; i++) {
List<?> eleList = (List<?>) objList.get(i);
Class<?> dataClass = eleList.get(0).getClass();
// 创建sheet
sheet = this.sheet(sheets[i], dataClass, responseExcel.template(), responseExcel.headGenerator());

if (CollectionUtils.isEmpty(eleList)) {
sheet = EasyExcel.writerSheet(responseExcel.sheets()[i].sheetName()).build();
}
else {
// 有模板则不指定sheet名
Class<?> dataClass = eleList.get(0).getClass();
sheet = this.sheet(responseExcel.sheets()[i], dataClass, responseExcel.template(),
responseExcel.headGenerator());
}

// 填充 sheet
if (responseExcel.fill()) {
excelWriter.fill(eleList, sheet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pig4cloud.plugin.excel.handler;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.write.metadata.WriteSheet;
Expand All @@ -8,6 +9,7 @@
import com.pig4cloud.plugin.excel.enhance.WriterBuilderEnhancer;
import com.pig4cloud.plugin.excel.kit.ExcelException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
Expand Down Expand Up @@ -44,21 +46,27 @@ public boolean support(Object obj) {

@Override
public void write(Object obj, HttpServletResponse response, ResponseExcel responseExcel) {
List<?> list = (List<?>) obj;
List<?> eleList = (List<?>) obj;
ExcelWriter excelWriter = getExcelWriter(response, responseExcel);

// 有模板则不指定sheet名
Class<?> dataClass = list.get(0).getClass();
WriteSheet sheet = this.sheet(responseExcel.sheets()[0], dataClass, responseExcel.template(),
responseExcel.headGenerator());
WriteSheet sheet;
if (CollectionUtils.isEmpty(eleList)) {
sheet = EasyExcel.writerSheet(responseExcel.sheets()[0].sheetName()).build();
}
else {
// 有模板则不指定sheet名
Class<?> dataClass = eleList.get(0).getClass();
sheet = this.sheet(responseExcel.sheets()[0], dataClass, responseExcel.template(),
responseExcel.headGenerator());
}

// 填充 sheet
if (responseExcel.fill()) {
excelWriter.fill(list, sheet);
excelWriter.fill(eleList, sheet);
}
else {
// 写入sheet
excelWriter.write(list, sheet);
excelWriter.write(eleList, sheet);
}
excelWriter.finish();
}
Expand Down

0 comments on commit 831275d

Please sign in to comment.