Browse Source

注解支持下拉

4.1.3.A
jueyue 4 years ago
parent
commit
2c103e9192
5 changed files with 68 additions and 1 deletions
  1. +5
    -0
      easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java
  2. +5
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java
  3. +43
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java
  4. +1
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java
  5. +14
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelDictHandler.java

+ 5
- 0
easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java View File

@@ -119,6 +119,11 @@ public @interface Excel {
*/
public String dict() default "";
/**
* 下拉列表,仅支持replace和dict,dict优先
* @return
*/
public boolean addressList() default false;
/**
* 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/
*


+ 5
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java View File

@@ -71,7 +71,11 @@ public class ExcelBaseEntity {
/**
* 时区
*/
private String timezone;
private String timezone;
/**
* 是否插入下拉
*/
private boolean addressList;
private List<Method> methods;


+ 43
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java View File

@@ -29,6 +29,7 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;

import java.lang.reflect.Field;
import java.util.*;
@@ -240,6 +241,7 @@ public class ExcelExportService extends BaseExportService {
setColumnHidden(excelParams, sheet);
short rowHeight = entity.getHeight() != 0 ? entity.getHeight() : getRowHeight(excelParams);
setCurrentIndex(1);
createAddressList(sheet, index, excelParams, 0);
Iterator<?> its = dataSet.iterator();
List<Object> tempList = new ArrayList<Object>();
while (its.hasNext()) {
@@ -279,5 +281,46 @@ public class ExcelExportService extends BaseExportService {
}
}

/**
* 插入下拉
*
* @param sheet
* @param index
* @param excelParams
*/
private int createAddressList(Sheet sheet, int index, List<ExcelExportEntity> excelParams, int cellIndex) {
for (int i = 0; i < excelParams.size(); i++) {
if (excelParams.get(i).isAddressList()) {
ExcelExportEntity entity = excelParams.get(i);
CellRangeAddressList regions = new CellRangeAddressList(index,
this.type.equals(ExcelType.XSSF) ? 1000000 : 65535, cellIndex, cellIndex);
sheet.addValidationData(sheet.getDataValidationHelper().createValidation(sheet.getDataValidationHelper().createExplicitListConstraint(getAddressListValues(entity)), regions));
}
if (excelParams.get(i).getList() != null) {
cellIndex = createAddressList(sheet, index, excelParams.get(i).getList(), cellIndex);
} else {
cellIndex++;
}
}
return cellIndex;
}

private String[] getAddressListValues(ExcelExportEntity entity) {
if (StringUtils.isNotEmpty(entity.getDict())) {
String[] arr = new String[this.dictHandler.getList(entity.getDict()).size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = this.dictHandler.getList(entity.getDict()).get(i).get("dictValue").toString();
}
return arr;
} else if (entity.getReplace() != null && entity.getReplace().length > 0) {
String[] arr = new String[entity.getReplace().length];
for (int i = 0; i < arr.length; i++) {
arr[i] = entity.getReplace()[i].split("_")[0];
}
return arr;
}
throw new ExcelExportException(entity.getName() + "没有可以创建下来的数据,请addressList不要设置为true");
}


}

+ 1
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java View File

@@ -274,6 +274,7 @@ public class ExportCommonService {
excelEntity.setDict(excel.dict());
excelEntity.setEnumExportField(excel.enumExportField());
excelEntity.setTimezone(excel.timezone());
excelEntity.setAddressList(excel.addressList());
if (excelGroup != null) {
excelEntity.setGroupName(PoiPublicUtil.getValueByTargetId(excelGroup.name(), targetId, null));
} else {


+ 14
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelDictHandler.java View File

@@ -1,11 +1,25 @@
package cn.afterturn.easypoi.handler.inter;

import java.util.List;
import java.util.Map;

/**
* @author jueyue on 18-2-2.
* @version 3.0.4
*/
public interface IExcelDictHandler {

/**
* 返回字典所有值
* key: dictKey
* value: dictValue
* @param dict 字典Key
* @return
*/
default public List<Map> getList(String dict) {
return null;
}

/**
* 从值翻译到名称
*


Loading…
Cancel
Save