From 52df21d5545cac282cccdd9dd8efc3f67091445a Mon Sep 17 00:00:00 2001 From: hccake Date: Wed, 28 Apr 2021 22:31:50 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20header=20=E6=97=B6=EF=BC=8C=E5=9C=A8=20wri?= =?UTF-8?q?teSheet=20=E5=AF=B9=E8=B1=A1=E4=B8=8A=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E5=BF=BD=E7=95=A5=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../write/executor/ExcelWriteAddExecutor.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 9f229029..bd655776 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -1,16 +1,5 @@ package com.alibaba.excel.write.executor; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; - import com.alibaba.excel.context.WriteContext; import com.alibaba.excel.enums.HeadKindEnum; import com.alibaba.excel.metadata.CellData; @@ -20,13 +9,20 @@ import com.alibaba.excel.util.ClassUtils; import com.alibaba.excel.util.CollectionUtils; import com.alibaba.excel.util.WorkBookUtil; import com.alibaba.excel.util.WriteHandlerUtils; -import com.alibaba.excel.write.metadata.WriteWorkbook; import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder; import com.alibaba.excel.write.metadata.holder.WriteHolder; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; -import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; - import net.sf.cglib.beans.BeanMap; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; /** * Add the data into excel @@ -171,14 +167,17 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { if (!sortedAllFiledMap.isEmpty()) { return; } - WriteWorkbookHolder writeWorkbookHolder = writeContext.writeWorkbookHolder(); - boolean needIgnore = - !CollectionUtils.isEmpty(writeWorkbookHolder.getExcludeColumnFiledNames()) || !CollectionUtils - .isEmpty(writeWorkbookHolder.getExcludeColumnIndexes()) || !CollectionUtils - .isEmpty(writeWorkbookHolder.getIncludeColumnFiledNames()) || !CollectionUtils - .isEmpty(writeWorkbookHolder.getIncludeColumnIndexes()); + + // 获取当前的使用的 holder + WriteHolder holder = writeContext.currentWriteHolder(); + boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( + !CollectionUtils.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnFiledNames()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder) holder).getExcludeColumnIndexes()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFiledNames()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes())); + ClassUtils.declaredFields(clazz, sortedAllFiledMap, - writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder); + writeContext.writeWorkbookHolder().getWriteWorkbook().getConvertAllFiled(), needIgnore, holder); } }