|
|
@ -24,20 +24,11 @@ import com.alibaba.excel.write.metadata.RowData; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; |
|
|
|
|
|
|
|
|
|
|
|
import net.sf.cglib.beans.BeanMap; |
|
|
|
import net.sf.cglib.beans.BeanMap; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
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 |
|
|
|
* Add the data into excel |
|
|
@ -94,14 +85,15 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { |
|
|
|
} |
|
|
|
} |
|
|
|
Map<Integer, Head> headMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadMap(); |
|
|
|
Map<Integer, Head> headMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadMap(); |
|
|
|
int dataIndex = 0; |
|
|
|
int dataIndex = 0; |
|
|
|
int cellIndex = 0; |
|
|
|
int maxCellIndex = -1; |
|
|
|
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) { |
|
|
|
if (dataIndex >= oneRowData.size()) { |
|
|
|
if (dataIndex >= oneRowData.size()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
cellIndex = entry.getKey(); |
|
|
|
int cellIndex = entry.getKey(); |
|
|
|
Head head = entry.getValue(); |
|
|
|
Head head = entry.getValue(); |
|
|
|
doAddBasicTypeToExcel(oneRowData, head, row, relativeRowIndex, dataIndex++, cellIndex); |
|
|
|
doAddBasicTypeToExcel(oneRowData, head, row, relativeRowIndex, dataIndex++, cellIndex); |
|
|
|
|
|
|
|
maxCellIndex = Math.max(maxCellIndex, cellIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
// Finish
|
|
|
|
// Finish
|
|
|
|
if (dataIndex >= oneRowData.size()) { |
|
|
|
if (dataIndex >= oneRowData.size()) { |
|
|
@ -109,12 +101,11 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { |
|
|
|
} |
|
|
|
} |
|
|
|
// fix https://github.com/alibaba/easyexcel/issues/1702
|
|
|
|
// fix https://github.com/alibaba/easyexcel/issues/1702
|
|
|
|
// If there is data, it is written to the next cell
|
|
|
|
// If there is data, it is written to the next cell
|
|
|
|
if (dataIndex != 0) { |
|
|
|
maxCellIndex++; |
|
|
|
cellIndex++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int size = oneRowData.size() - dataIndex; |
|
|
|
int size = oneRowData.size() - dataIndex; |
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
doAddBasicTypeToExcel(oneRowData, null, row, relativeRowIndex, dataIndex++, cellIndex++); |
|
|
|
doAddBasicTypeToExcel(oneRowData, null, row, relativeRowIndex, dataIndex++, maxCellIndex++); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -134,14 +125,14 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { |
|
|
|
WriteHolder currentWriteHolder = writeContext.currentWriteHolder(); |
|
|
|
WriteHolder currentWriteHolder = writeContext.currentWriteHolder(); |
|
|
|
BeanMap beanMap = BeanMapUtils.create(oneRowData); |
|
|
|
BeanMap beanMap = BeanMapUtils.create(oneRowData); |
|
|
|
Set<String> beanMapHandledSet = new HashSet<String>(); |
|
|
|
Set<String> beanMapHandledSet = new HashSet<String>(); |
|
|
|
int cellIndex; |
|
|
|
int maxCellIndex = -1; |
|
|
|
// If it's a class it needs to be cast by type
|
|
|
|
// If it's a class it needs to be cast by type
|
|
|
|
if (HeadKindEnum.CLASS.equals(writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadKind())) { |
|
|
|
if (HeadKindEnum.CLASS.equals(writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadKind())) { |
|
|
|
Map<Integer, Head> headMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadMap(); |
|
|
|
Map<Integer, Head> headMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getHeadMap(); |
|
|
|
Map<Integer, ExcelContentProperty> contentPropertyMap = |
|
|
|
Map<Integer, ExcelContentProperty> contentPropertyMap = |
|
|
|
writeContext.currentWriteHolder().excelWriteHeadProperty().getContentPropertyMap(); |
|
|
|
writeContext.currentWriteHolder().excelWriteHeadProperty().getContentPropertyMap(); |
|
|
|
for (Map.Entry<Integer, ExcelContentProperty> entry : contentPropertyMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, ExcelContentProperty> entry : contentPropertyMap.entrySet()) { |
|
|
|
cellIndex = entry.getKey(); |
|
|
|
int cellIndex = entry.getKey(); |
|
|
|
ExcelContentProperty excelContentProperty = entry.getValue(); |
|
|
|
ExcelContentProperty excelContentProperty = entry.getValue(); |
|
|
|
String name = FieldUtils.resolveCglibFieldName(excelContentProperty.getField()); |
|
|
|
String name = FieldUtils.resolveCglibFieldName(excelContentProperty.getField()); |
|
|
|
if (!beanMap.containsKey(name)) { |
|
|
|
if (!beanMap.containsKey(name)) { |
|
|
@ -157,13 +148,15 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { |
|
|
|
null, cell, value, excelContentProperty, head, relativeRowIndex); |
|
|
|
null, cell, value, excelContentProperty, head, relativeRowIndex); |
|
|
|
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE); |
|
|
|
WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE); |
|
|
|
beanMapHandledSet.add(name); |
|
|
|
beanMapHandledSet.add(name); |
|
|
|
|
|
|
|
maxCellIndex = Math.max(maxCellIndex, cellIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
cellIndex++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Finish
|
|
|
|
// Finish
|
|
|
|
if (beanMapHandledSet.size() == beanMap.size()) { |
|
|
|
if (beanMapHandledSet.size() == beanMap.size()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
maxCellIndex++; |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Field> ignoreMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getIgnoreMap(); |
|
|
|
Map<String, Field> ignoreMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getIgnoreMap(); |
|
|
|
initSortedAllFiledMapFieldList(oneRowData.getClass(), sortedAllFiledMap); |
|
|
|
initSortedAllFiledMapFieldList(oneRowData.getClass(), sortedAllFiledMap); |
|
|
|
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) { |
|
|
@ -175,8 +168,10 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
Object value = beanMap.get(filedName); |
|
|
|
Object value = beanMap.get(filedName); |
|
|
|
WriteHandlerUtils.beforeCellCreate(writeContext, row, null, cellIndex, relativeRowIndex, Boolean.FALSE); |
|
|
|
WriteHandlerUtils.beforeCellCreate(writeContext, row, null, maxCellIndex, relativeRowIndex, Boolean.FALSE); |
|
|
|
Cell cell = WorkBookUtil.createCell(row, cellIndex++); |
|
|
|
// fix https://github.com/alibaba/easyexcel/issues/1870
|
|
|
|
|
|
|
|
// If there is data, it is written to the next cell
|
|
|
|
|
|
|
|
Cell cell = WorkBookUtil.createCell(row, maxCellIndex++); |
|
|
|
WriteHandlerUtils.afterCellCreate(writeContext, cell, null, relativeRowIndex, Boolean.FALSE); |
|
|
|
WriteHandlerUtils.afterCellCreate(writeContext, cell, null, relativeRowIndex, Boolean.FALSE); |
|
|
|
WriteCellData<?> cellData = converterAndSet(currentWriteHolder, |
|
|
|
WriteCellData<?> cellData = converterAndSet(currentWriteHolder, |
|
|
|
FieldUtils.getFieldClass(beanMap, filedName), null, cell, value, null, null, relativeRowIndex); |
|
|
|
FieldUtils.getFieldClass(beanMap, filedName), null, cell, value, null, null, relativeRowIndex); |
|
|
|