|
|
@ -1,20 +1,5 @@ |
|
|
|
package com.alibaba.excel.util; |
|
|
|
package com.alibaba.excel.util; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.TreeMap; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.annotation.ExcelIgnore; |
|
|
|
import com.alibaba.excel.annotation.ExcelIgnore; |
|
|
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
|
|
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
|
|
|
import com.alibaba.excel.annotation.ExcelProperty; |
|
|
|
import com.alibaba.excel.annotation.ExcelProperty; |
|
|
@ -34,7 +19,6 @@ import com.alibaba.excel.metadata.property.FontProperty; |
|
|
|
import com.alibaba.excel.metadata.property.NumberFormatProperty; |
|
|
|
import com.alibaba.excel.metadata.property.NumberFormatProperty; |
|
|
|
import com.alibaba.excel.metadata.property.StyleProperty; |
|
|
|
import com.alibaba.excel.metadata.property.StyleProperty; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
import com.alibaba.excel.write.metadata.holder.WriteHolder; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
import lombok.EqualsAndHashCode; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.Getter; |
|
|
@ -42,6 +26,11 @@ import lombok.Setter; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.springframework.cglib.beans.BeanMap; |
|
|
|
import org.springframework.cglib.beans.BeanMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
|
|
* contributor license agreements. See the NOTICE file distributed with |
|
|
|
* contributor license agreements. See the NOTICE file distributed with |
|
|
@ -49,7 +38,7 @@ import org.springframework.cglib.beans.BeanMap; |
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
|
|
* (the "License"); you may not use this file except in compliance with |
|
|
|
* (the "License"); you may not use this file except in compliance with |
|
|
|
* the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* |
|
|
|
* <p> |
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
@ -102,7 +91,8 @@ public class ClassUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ExcelContentProperty declaredExcelContentProperty(Map<?, ?> dataMap, Class<?> headClazz, |
|
|
|
public static ExcelContentProperty declaredExcelContentProperty(Map<?, ?> dataMap, Class<?> headClazz, |
|
|
|
String fieldName, ConfigurationHolder configurationHolder) { |
|
|
|
String fieldName, |
|
|
|
|
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
Class<?> clazz = null; |
|
|
|
Class<?> clazz = null; |
|
|
|
if (dataMap instanceof BeanMap) { |
|
|
|
if (dataMap instanceof BeanMap) { |
|
|
|
Object bean = ((BeanMap) dataMap).getBean(); |
|
|
|
Object bean = ((BeanMap) dataMap).getBean(); |
|
|
@ -137,7 +127,8 @@ public class ClassUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static ExcelContentProperty doGetExcelContentProperty(Class<?> clazz, Class<?> headClass, |
|
|
|
private static ExcelContentProperty doGetExcelContentProperty(Class<?> clazz, Class<?> headClass, |
|
|
|
String fieldName, ConfigurationHolder configurationHolder) { |
|
|
|
String fieldName, |
|
|
|
|
|
|
|
ConfigurationHolder configurationHolder) { |
|
|
|
ExcelContentProperty excelContentProperty = Optional.ofNullable( |
|
|
|
ExcelContentProperty excelContentProperty = Optional.ofNullable( |
|
|
|
declaredFieldContentMap(clazz, configurationHolder)) |
|
|
|
declaredFieldContentMap(clazz, configurationHolder)) |
|
|
|
.map(map -> map.get(fieldName)) |
|
|
|
.map(map -> map.get(fieldName)) |
|
|
@ -333,7 +324,7 @@ public class ClassUtils { |
|
|
|
return fieldCache; |
|
|
|
return fieldCache; |
|
|
|
} |
|
|
|
} |
|
|
|
// ignore filed
|
|
|
|
// ignore filed
|
|
|
|
Map<Integer, FieldWrapper> tempSortedFieldMapp = MapUtils.newHashMap(); |
|
|
|
Map<Integer, FieldWrapper> tempSortedFieldMap = MapUtils.newHashMap(); |
|
|
|
int index = 0; |
|
|
|
int index = 0; |
|
|
|
for (Map.Entry<Integer, FieldWrapper> entry : sortedFieldMap.entrySet()) { |
|
|
|
for (Map.Entry<Integer, FieldWrapper> entry : sortedFieldMap.entrySet()) { |
|
|
|
Integer key = entry.getKey(); |
|
|
|
Integer key = entry.getKey(); |
|
|
@ -346,18 +337,18 @@ public class ClassUtils { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Mandatory sorted fields
|
|
|
|
// Mandatory sorted fields
|
|
|
|
if (indexFieldMap.containsKey(key)) { |
|
|
|
if (indexFieldMap.containsKey(key)) { |
|
|
|
tempSortedFieldMapp.put(key, field); |
|
|
|
tempSortedFieldMap.put(key, field); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Need to reorder automatically
|
|
|
|
// Need to reorder automatically
|
|
|
|
// Check whether the current key is already in use
|
|
|
|
// Check whether the current key is already in use
|
|
|
|
while (tempSortedFieldMapp.containsKey(index)) { |
|
|
|
while (tempSortedFieldMap.containsKey(index)) { |
|
|
|
index++; |
|
|
|
index++; |
|
|
|
} |
|
|
|
} |
|
|
|
tempSortedFieldMapp.put(index++, field); |
|
|
|
tempSortedFieldMap.put(index++, field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fieldCache.setSortedFieldMap(tempSortedFieldMapp); |
|
|
|
fieldCache.setSortedFieldMap(tempSortedFieldMap); |
|
|
|
|
|
|
|
|
|
|
|
// resort field
|
|
|
|
// resort field
|
|
|
|
resortField(writeHolder, fieldCache); |
|
|
|
resortField(writeHolder, fieldCache); |
|
|
@ -365,9 +356,9 @@ public class ClassUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* it only works when {@link WriteHolder#getIncludeColumnFieldNames()} or |
|
|
|
* it only works when {@link WriteHolder#includeColumnFieldNames()} or |
|
|
|
* {@link WriteHolder#getIncludeColumnIndexes()} ()} has value |
|
|
|
* {@link WriteHolder#includeColumnIndexes()} has value |
|
|
|
* and {@link WriteHolder#getOrderByIncludeColumn()} ()} is true |
|
|
|
* and {@link WriteHolder#orderByIncludeColumn()} is true |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
private static void resortField(WriteHolder writeHolder, FieldCache fieldCache) { |
|
|
|
private static void resortField(WriteHolder writeHolder, FieldCache fieldCache) { |
|
|
|
if (!writeHolder.orderByIncludeColumn()) { |
|
|
|
if (!writeHolder.orderByIncludeColumn()) { |
|
|
|