支持Excel导出对象的多个子列表
This commit is contained in:
@@ -130,12 +130,12 @@ public class ExcelUtil<T> {
|
|||||||
/**
|
/**
|
||||||
* 对象的子列表方法
|
* 对象的子列表方法
|
||||||
*/
|
*/
|
||||||
private Map<String, Method> subMethods = new HashMap<>();
|
private Map<String, Method> subMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象的子列表属性
|
* 对象的子列表属性
|
||||||
*/
|
*/
|
||||||
private Map<String, List<Field>> subFieldsMap = new HashMap<>();
|
private Map<String, List<Field>> subFieldsMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计列表
|
* 统计列表
|
||||||
@@ -200,7 +200,10 @@ public class ExcelUtil<T> {
|
|||||||
if (StringUtils.isNotEmpty(title)) {
|
if (StringUtils.isNotEmpty(title)) {
|
||||||
int titleLastCol = this.fields.size() - 1;
|
int titleLastCol = this.fields.size() - 1;
|
||||||
if (isSubList()) {
|
if (isSubList()) {
|
||||||
titleLastCol = titleLastCol + subFieldsMap.values().size() - 1;
|
for (List<Field> currentSubFields : subFieldsMap.values())
|
||||||
|
{
|
||||||
|
titleLastCol = titleLastCol + currentSubFields.size() - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
||||||
titleRow.setHeightInPoints(30);
|
titleRow.setHeightInPoints(30);
|
||||||
@@ -598,9 +601,9 @@ public class ExcelUtil<T> {
|
|||||||
if (Collection.class.isAssignableFrom(field.getType())) {
|
if (Collection.class.isAssignableFrom(field.getType())) {
|
||||||
try {
|
try {
|
||||||
Collection<?> subList = (Collection<?>) getTargetValue(vo, field, excel);
|
Collection<?> subList = (Collection<?>) getTargetValue(vo, field, excel);
|
||||||
|
List<Field> currentSubFields = subFieldsMap.get(field.getName());
|
||||||
if (subList != null && !subList.isEmpty()) {
|
if (subList != null && !subList.isEmpty()) {
|
||||||
int subIndex = 0;
|
int subIndex = 0;
|
||||||
List<Field> currentSubFields = subFieldsMap.get(field.getName());
|
|
||||||
for (Object subVo : subList) {
|
for (Object subVo : subList) {
|
||||||
Row subRow = sheet.getRow(currentRowNum + subIndex);
|
Row subRow = sheet.getRow(currentRowNum + subIndex);
|
||||||
if (subRow == null) {
|
if (subRow == null) {
|
||||||
@@ -614,8 +617,8 @@ public class ExcelUtil<T> {
|
|||||||
}
|
}
|
||||||
subIndex++;
|
subIndex++;
|
||||||
}
|
}
|
||||||
column += currentSubFields.size();
|
|
||||||
}
|
}
|
||||||
|
column += currentSubFields.size();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("填充集合数据失败", e);
|
log.error("填充集合数据失败", e);
|
||||||
}
|
}
|
||||||
@@ -1275,6 +1278,8 @@ public class ExcelUtil<T> {
|
|||||||
public List<Object[]> getFields() {
|
public List<Object[]> getFields() {
|
||||||
List<Object[]> fields = new ArrayList<Object[]>();
|
List<Object[]> fields = new ArrayList<Object[]>();
|
||||||
List<Field> tempFields = new ArrayList<>();
|
List<Field> tempFields = new ArrayList<>();
|
||||||
|
subFieldsMap = new HashMap<>();
|
||||||
|
subMethods = new HashMap<>();
|
||||||
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
||||||
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||||
if (StringUtils.isNotEmpty(includeFields)) {
|
if (StringUtils.isNotEmpty(includeFields)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user