Java Code Examples for org.jeecgframework.poi.excel.entity.params.ExcelExportEntity#getReplace()

The following examples show how to use org.jeecgframework.poi.excel.entity.params.ExcelExportEntity#getReplace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportBase.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取填如这个cell的值,提供一些附加功能
 * 
 * @param entity
 * @param obj
 * @return
 * @throws Exception
 */
public Object getCellValue(ExcelExportEntity entity, Object obj) throws Exception {
	Object value;
	if (obj instanceof Map) {
		value = ((Map<?, ?>) obj).get(entity.getKey());
	} else {
		value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {});
	}
	if (StringUtils.isNotEmpty(entity.getFormat())) {
		value = formatValue(value, entity);
	}
	if (entity.getReplace() != null && entity.getReplace().length > 0) {
		value = replaceValue(entity.getReplace(), String.valueOf(value));
	}
	if (needHanlderList != null && needHanlderList.contains(entity.getName())) {
		value = dataHanlder.exportHandler(obj, entity.getName(), value);
	}
	if (StringUtils.isNotEmpty(entity.getSuffix()) && value != null) {
		value = value + entity.getSuffix();
	}
	return value == null ? "" : value.toString();
}
 
Example 2
Source File: ExportBase.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取填如这个cell的值,提供一些附加功能
 * 
 * @param entity
 * @param obj
 * @return
 * @throws Exception
 */
public Object getCellValue(ExcelExportEntity entity, Object obj) throws Exception {
    Object value;
    if (obj instanceof Map) {
        value = ((Map<?, ?>) obj).get(entity.getKey());
    } else {
        value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj)
            : entity.getMethod().invoke(obj, new Object[] {});
    }
    if (StringUtils.isNotEmpty(entity.getFormat())) {
        value = formatValue(value, entity);
    }
    if (entity.getReplace() != null && entity.getReplace().length > 0) {
        value = replaceValue(entity.getReplace(), String.valueOf(value));
    }
    if (needHanlderList != null && needHanlderList.contains(entity.getName())) {
        value = dataHanlder.exportHandler(obj, entity.getName(), value);
    }
    if (StringUtils.isNotEmpty(entity.getSuffix()) && value != null) {
        value = value + entity.getSuffix();
    }
    return value == null ? "" : value.toString();
}
 
Example 3
Source File: ExportBase.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取填如这个cell的值,提供一些附加功能
 * 
 * @param entity
 * @param obj
 * @return
 * @throws Exception
 */
public Object getCellValue(ExcelExportEntity entity, Object obj) throws Exception {
	Object value;
	if (obj instanceof Map) {
		value = ((Map<?, ?>) obj).get(entity.getKey());
	} else {
		value = entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {});
	}
	//update-begin-author:taoyan date:2020319 for:Excel注解的numFormat方法似乎未实现 #970
	if (StringUtils.isNotEmpty(entity.getNumFormat()) && value!=null) {
		value = new DecimalFormat(entity.getNumFormat()).format(value);
	}
	//update-end-author:taoyan date:2020319 for:Excel注解的numFormat方法似乎未实现 #970

	if (StringUtils.isNotEmpty(entity.getFormat())) {
		value = formatValue(value, entity);
	}
	if (entity.getReplace() != null && entity.getReplace().length > 0) {
		//update-begin-author:taoyan date:20180731 for:TASK #3038 【bug】Excel 导出多个值(逗号隔开的情况下,导出字典值是ID值)
		if(value == null){
			value = "";//String.valueOf(value) 如果value为null 则返回"null"
		}
		if(entity.isMultiReplace()){
			value = multiReplaceValue(entity.getReplace(), String.valueOf(value));
		}else{
			value = replaceValue(entity.getReplace(), String.valueOf(value));
		}
		//update-end-author:taoyan date:20180731 for:TASK #3038 【bug】Excel 导出多个值(逗号隔开的情况下,导出字典值是ID值)
	}
	if (needHanlderList != null && needHanlderList.contains(entity.getName())) {
		value = dataHanlder.exportHandler(obj, entity.getName(), value);
	}
	if (StringUtils.isNotEmpty(entity.getSuffix()) && value != null) {
		value = value + entity.getSuffix();
	}
	return value == null ? "" : value.toString();
}
 
Example 4
Source File: ExportBase.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 注解到导出对象的转换
 * 
 * @param targetId
 * @param field
 * @param excelEntity
 * @param excel
 * @param pojoClass
 * @throws Exception
 */
private void getExcelField(String targetId, Field field, ExcelExportEntity excelEntity, Excel excel, Class<?> pojoClass) throws Exception {
	excelEntity.setName(getExcelName(excel.name(), targetId));
	excelEntity.setWidth(excel.width());
	excelEntity.setHeight(excel.height());
	excelEntity.setNeedMerge(excel.needMerge());
	excelEntity.setMergeVertical(excel.mergeVertical());
	excelEntity.setMergeRely(excel.mergeRely());
	excelEntity.setReplace(excel.replace());
	if(StringUtils.isNotEmpty(excel.dicCode())){
		EasypoiDictServiceI jeecgDictService = null;
		try {
			jeecgDictService = ApplicationContextUtil.getContext().getBean(EasypoiDictServiceI.class);
		} catch (Exception e) {
		}
		if(jeecgDictService!=null){
			 String[] dictReplace = jeecgDictService.queryDict(excel.dictTable(), excel.dicCode(), excel.dicText());
			 if(excelEntity.getReplace()!=null && dictReplace!=null && dictReplace.length!=0){
				 excelEntity.setReplace(dictReplace);
			 }
		}
	}
	excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId));
	excelEntity.setWrap(excel.isWrap());
	excelEntity.setExportImageType(excel.imageType());
	excelEntity.setSuffix(excel.suffix());
	excelEntity.setDatabaseFormat(excel.databaseFormat());
	excelEntity.setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel.exportFormat() : excel.format());
	excelEntity.setStatistics(excel.isStatistics());
	String fieldname = field.getName();
	excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass));
}
 
Example 5
Source File: ExportBase.java    From autopoi with Apache License 2.0 4 votes vote down vote up
/**
 * 注解到导出对象的转换
 * 
 * @param targetId
 * @param field
 * @param excelEntity
 * @param excel
 * @param pojoClass
 * @throws Exception
 */
private void getExcelField(String targetId, Field field, ExcelExportEntity excelEntity, Excel excel, Class<?> pojoClass) throws Exception {
	excelEntity.setName(getExcelName(excel.name(), targetId));
	excelEntity.setWidth(excel.width());
	excelEntity.setHeight(excel.height());
	excelEntity.setNeedMerge(excel.needMerge());
	excelEntity.setMergeVertical(excel.mergeVertical());
	excelEntity.setMergeRely(excel.mergeRely());
	excelEntity.setReplace(excel.replace());
	if(StringUtils.isNotEmpty(excel.dicCode())){
		AutoPoiDictServiceI jeecgDictService = null;
		try {
			jeecgDictService = ApplicationContextUtil.getContext().getBean(AutoPoiDictServiceI.class);
		} catch (Exception e) {
		}
		if(jeecgDictService!=null){
			 String[] dictReplace = jeecgDictService.queryDict(excel.dictTable(), excel.dicCode(), excel.dicText());
			 if(excelEntity.getReplace()!=null && dictReplace!=null && dictReplace.length!=0){
				 excelEntity.setReplace(dictReplace);
			 }
		}
	}
	excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId));
	excelEntity.setWrap(excel.isWrap());
	excelEntity.setExportImageType(excel.imageType());
	excelEntity.setSuffix(excel.suffix());
	excelEntity.setDatabaseFormat(excel.databaseFormat());
	excelEntity.setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel.exportFormat() : excel.format());
	excelEntity.setStatistics(excel.isStatistics());
	String fieldname = field.getName();
	//update-begin-author:taoyan date:20200319 for:autopoi 双表头问题 #862 基于注解的解决方案
	excelEntity.setKey(fieldname);
	//update-end-author:taoyan date:20200319 for:autopoi 双表头问题 #862 基于注解的解决方案
	//update-begin-author:taoyan date:20200319 for:Excel注解的numFormat方法似乎未实现 #970
	excelEntity.setNumFormat(excel.numFormat());
	//update-end-author:taoyan date:20200319 for:Excel注解的numFormat方法似乎未实现 #970
	//update-begin-author:taoyan date:20180615 for:TASK #2798 【例子】导入扩展方法,支持自定义导入字段转换规则
	excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass,excel.exportConvert()));
	//update-end-author:taoyan date:20180615 for:TASK #2798 【例子】导入扩展方法,支持自定义导入字段转换规则
	//update-begin-author:taoyan date:20180801 for:TASK #3038 【bug】Excel 导出多个值(逗号隔开的情况下,导出字典值是ID值)
	excelEntity.setMultiReplace(excel.multiReplace());
	//update-end-author:taoyan date:20180801 for:TASK #3038 【bug】Excel 导出多个值(逗号隔开的情况下,导出字典值是ID值)
	//update-begin-author:taoyan date:20200319 for:autopoi 双表头问题 #862 基于实体注解的解决方案
	if(StringUtils.isNotEmpty(excel.groupName())){
		excelEntity.setGroupName(excel.groupName());
		excelEntity.setColspan(true);
	}
	//update-end-author:taoyan date:20200319 for:autopoi 双表头问题 #862 基于实体注解的解决方案
}