org.jeecgframework.poi.excel.entity.params.ExcelImportEntity Java Examples

The following examples show how to use org.jeecgframework.poi.excel.entity.params.ExcelImportEntity. 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: CellValueServer.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取cell的值
 * 
 * @param object
 * @param excelParams
 * @param cell
 * @param titleString
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception {
	ExcelImportEntity entity = excelParams.get(titleString);
	String xclass = "class java.lang.Object";
	if (!(object instanceof Map)) {
		Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
		Type[] ts = setMethod.getGenericParameterTypes();
		xclass = ts[0].toString();
	}
	Object result = getCellValue(xclass, cell, entity);
	if (entity != null) {
		result = hanlderSuffix(entity.getSuffix(), result);
		//update-begin-author:taoYan date:20180807 for:多值替换
		result = replaceValue(entity.getReplace(), result,entity.isMultiReplace());
		//update-end-author:taoYan date:20180807 for:多值替换
	}
	result = hanlderValue(dataHanlder, object, result, titleString);
	return getValueByType(xclass, result, entity);
}
 
Example #2
Source File: ExcelImportServer.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存字段值(获取值,校验值,追加错误信息)
 * 
 * @param params
 * @param object
 * @param cell
 * @param excelParams
 * @param titleString
 * @param row
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString, Row row) throws Exception {
	Object value = cellValueServer.getValue(params.getDataHanlder(), object, cell, excelParams, titleString);
	if (object instanceof Map) {
		if (params.getDataHanlder() != null) {
			params.getDataHanlder().setMapValue((Map) object, titleString, value);
		} else {
			((Map) object).put(titleString, value);
		}
	} else {
		ExcelVerifyHanlderResult verifyResult = verifyHandlerServer.verifyData(object, value, titleString, excelParams.get(titleString).getVerify(), params.getVerifyHanlder());
		if (verifyResult.isSuccess()) {
			setValues(excelParams.get(titleString), object, value);
		} else {
			Cell errorCell = row.createCell(row.getLastCellNum());
			errorCell.setCellValue(verifyResult.getMsg());
			errorCell.setCellStyle(errorCellStyle);
			verfiyFail = true;
			throw new ExcelImportException(ExcelImportEnum.VERIFY_ERROR);
		}
	}
}
 
Example #3
Source File: CellValueServer.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取cell的值
 * 
 * @param object
 * @param excelParams
 * @param cell
 * @param titleString
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception {
	ExcelImportEntity entity = excelParams.get(titleString);
	String xclass = "class java.lang.Object";
	if (!(object instanceof Map)) {
		Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
		Type[] ts = setMethod.getGenericParameterTypes();
		xclass = ts[0].toString();
	}
	Object result = getCellValue(xclass, cell, entity);
	if (entity != null) {
		result = hanlderSuffix(entity.getSuffix(), result);
		result = replaceValue(entity.getReplace(), result);
	}
	result = hanlderValue(dataHanlder, object, result, titleString);
	return getValueByType(xclass, result, entity);
}
 
Example #4
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
public void getExcelFieldList(String targetId, Field[] fields, Class<?> pojoClass, Map<String, ExcelImportEntity> temp, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass, field.getType()));
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(field.getType()), field.getType(), temp, newMethods);
		}
	}
}
 
Example #5
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 6 votes vote down vote up
public void getExcelFieldList(String targetId, Field[] fields, Class<?> pojoClass,
                              Map<String, ExcelImportEntity> temp, List<Method> getMethods)
                                                                                           throws Exception {
    ExcelImportEntity excelEntity = null;
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
            continue;
        }
        if (PoiPublicUtil.isJavaClass(field)) {
            addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp);
        } else {
            List<Method> newMethods = new ArrayList<Method>();
            if (getMethods != null) {
                newMethods.addAll(getMethods);
            }
            newMethods
                .add(PoiPublicUtil.getMethod(field.getName(), pojoClass, field.getType()));
            getExcelFieldList(targetId, PoiPublicUtil.getClassFields(field.getType()),
                field.getType(), temp, newMethods);
        }
    }
}
 
Example #6
Source File: ExcelImportServer.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存字段值(获取值,校验值,追加错误信息)
 * 
 * @param params
 * @param object
 * @param cell
 * @param excelParams
 * @param titleString
 * @param row
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, Cell cell, Map<String, ExcelImportEntity> excelParams, String titleString, Row row) throws Exception {
	Object value = cellValueServer.getValue(params.getDataHanlder(), object, cell, excelParams, titleString);
	if (object instanceof Map) {
		if (params.getDataHanlder() != null) {
			params.getDataHanlder().setMapValue((Map) object, titleString, value);
		} else {
			((Map) object).put(titleString, value);
		}
	} else {
		ExcelVerifyHanlderResult verifyResult = verifyHandlerServer.verifyData(object, value, titleString, excelParams.get(titleString).getVerify(), params.getVerifyHanlder());
		if (verifyResult.isSuccess()) {
			setValues(excelParams.get(titleString), object, value);
		} else {
			Cell errorCell = row.createCell(row.getLastCellNum());
			errorCell.setCellValue(verifyResult.getMsg());
			errorCell.setCellStyle(errorCellStyle);
			verfiyFail = true;
			throw new ExcelImportException(ExcelImportEnum.VERIFY_ERROR);
		}
	}
}
 
Example #7
Source File: ExcelImportServer.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存字段值(获取值,校验值,追加错误信息)
 * 
 * @param params
 * @param object
 * @param cell
 * @param excelParams
 * @param titleString
 * @param row
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, Cell cell,
                            Map<String, ExcelImportEntity> excelParams, String titleString,
                            Row row) throws Exception {
    Object value = cellValueServer.getValue(params.getDataHanlder(), object, cell, excelParams,
        titleString);
    if (object instanceof Map) {
        if (params.getDataHanlder() != null) {
            params.getDataHanlder().setMapValue((Map) object, titleString, value);
        } else {
            ((Map) object).put(titleString, value);
        }
    } else {
        ExcelVerifyHanlderResult verifyResult = verifyHandlerServer.verifyData(object, value,
            titleString, excelParams.get(titleString).getVerify(), params.getVerifyHanlder());
        if (verifyResult.isSuccess()) {
            setValues(excelParams.get(titleString), object, value);
        } else {
            Cell errorCell = row.createCell(row.getLastCellNum());
            errorCell.setCellValue(verifyResult.getMsg());
            errorCell.setCellStyle(errorCellStyle);
            verfiyFail = true;
            throw new ExcelImportException(ExcelImportEnum.VERIFY_ERROR);
        }
    }
}
 
Example #8
Source File: CellValueServer.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取cell的值
 * 
 * @param object
 * @param excelParams
 * @param cell
 * @param titleString
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object, Cell cell,
                       Map<String, ExcelImportEntity> excelParams, String titleString)
                                                                                      throws Exception {
    ExcelImportEntity entity = excelParams.get(titleString);
    String xclass = "class java.lang.Object";
    if (!(object instanceof Map)) {
        Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity
            .getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
        Type[] ts = setMethod.getGenericParameterTypes();
        xclass = ts[0].toString();
    }
    Object result = getCellValue(xclass, cell, entity);
    if (entity != null) {
        result = hanlderSuffix(entity.getSuffix(), result);
        result = replaceValue(entity.getReplace(), result);
    }
    result = hanlderValue(dataHanlder, object, result, titleString);
    return getValueByType(xclass, result, entity);
}
 
Example #9
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 6 votes vote down vote up
public void getExcelFieldList(String targetId, Field[] fields, Class<?> pojoClass, Map<String, ExcelImportEntity> temp, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass, field.getType()));
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(field.getType()), field.getType(), temp, newMethods);
		}
	}
}
 
Example #10
Source File: ExcelImportServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取保存的真实路径
 * 
 * @param excelImportEntity
 * @param object
 * @return
 * @throws Exception
 */
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
    String url = "";
    if (excelImportEntity.getSaveUrl().equals("upload")) {
        if (excelImportEntity.getMethods() != null && excelImportEntity.getMethods().size() > 0) {
            object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
        }
        url = object.getClass().getName().split("\\.")[object.getClass().getName().split("\\.").length - 1];
        return excelImportEntity.getSaveUrl() + "/"
               + url.substring(0, url.lastIndexOf("Entity"));
    }
    return excelImportEntity.getSaveUrl();
}
 
Example #11
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 5 votes vote down vote up
public void getExcelField(String targetId, Field field, ExcelImportEntity excelEntity, Excel excel, Class<?> pojoClass) throws Exception {
	excelEntity.setName(getExcelName(excel.name(), targetId));
	String fieldname = field.getName();
	//update-begin-author:taoyan for:TASK #2798 【例子】导入扩展方法,支持自定义导入字段转换规则
	excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass, field.getType(),excel.importConvert()));
	//update-end-author:taoyan for:TASK #2798 【例子】导入扩展方法,支持自定义导入字段转换规则
	if (StringUtils.isNotEmpty(excel.importFormat())) {
		excelEntity.setFormat(excel.importFormat());
	} else {
		excelEntity.setFormat(excel.format());
	}
}
 
Example #12
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param entity
 * @param object
 * @param value
 * @throws Exception
 */
public void setValues(ExcelImportEntity entity, Object object, Object value) throws Exception {
    if (entity.getMethods() != null) {
        setFieldBySomeMethod(entity.getMethods(), object, value);
    } else {
        entity.getMethod().invoke(object, value);
    }
}
 
Example #13
Source File: CellValueServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取日期类型数据
 * 
 * @Author JueYue
 * @date 2013年11月26日
 * @param entity
 * @param value
 * @return
 */
private Date getDateData(ExcelImportEntity entity, String value) {
    if (StringUtils.isNotEmpty(entity.getFormat()) && StringUtils.isNotEmpty(value)) {
        SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
        try {
            return format.parse(value);
        } catch (ParseException e) {
            LOGGER.error("时间格式化失败,格式化:{},值:{}", entity.getFormat(), value);
            throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR);
        }
    }
    return null;
}
 
Example #14
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
public void getExcelField(String targetId, Field field, ExcelImportEntity excelEntity,
                          Excel excel, Class<?> pojoClass) throws Exception {
    excelEntity.setName(getExcelName(excel.name(), targetId));
    String fieldname = field.getName();
    excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass, field.getType()));
    if (StringUtils.isNotEmpty(excel.importFormat())) {
        excelEntity.setFormat(excel.importFormat());
    } else {
        excelEntity.setFormat(excel.format());
    }
}
 
Example #15
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields,
                             Map<String, ExcelImportEntity> excelParams,
                             List<ExcelCollectionParams> excelCollection, Class<?> pojoClass,
                             List<Method> getMethods) throws Exception {
    ExcelImportEntity excelEntity = null;
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
            continue;
        }
        if (PoiPublicUtil.isCollection(field.getType())) {
            // 集合对象设置属性
            ExcelCollectionParams collection = new ExcelCollectionParams();
            collection.setName(field.getName());
            Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
            ParameterizedType pt = (ParameterizedType) field.getGenericType();
            Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
            collection.setType(clz);
            getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
            collection.setExcelParams(temp);
            collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
            additionalCollectionName(collection);
            excelCollection.add(collection);
        } else if (PoiPublicUtil.isJavaClass(field)) {
            addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
        } else {
            List<Method> newMethods = new ArrayList<Method>();
            if (getMethods != null) {
                newMethods.addAll(getMethods);
            }
            newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
            getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()),
                excelParams, excelCollection, field.getType(), newMethods);
        }
    }
}
 
Example #16
Source File: CellValueServer.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取cell值
 * 
 * @param dataHanlder
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @return
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object, SaxReadCellEntity cellEntity, Map<String, ExcelImportEntity> excelParams, String titleString) {
	ExcelImportEntity entity = excelParams.get(titleString);
	Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
	Type[] ts = setMethod.getGenericParameterTypes();
	String xclass = ts[0].toString();
	Object result = cellEntity.getValue();
	result = hanlderSuffix(entity.getSuffix(), result);
	result = replaceValue(entity.getReplace(), result);
	result = hanlderValue(dataHanlder, object, result, titleString);
	return getValueByType(xclass, result, entity);
}
 
Example #17
Source File: CellValueServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取cell值
 * @param dataHanlder
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @return
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object,
                       SaxReadCellEntity cellEntity,
                       Map<String, ExcelImportEntity> excelParams, String titleString) {
    ExcelImportEntity entity = excelParams.get(titleString);
    Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity
        .getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
    Type[] ts = setMethod.getGenericParameterTypes();
    String xclass = ts[0].toString();
    Object result = cellEntity.getValue();
    result = hanlderSuffix(entity.getSuffix(), result);
    result = replaceValue(entity.getReplace(), result);
    result = hanlderValue(dataHanlder, object, result, titleString);
    return getValueByType(xclass, result, entity);
}
 
Example #18
Source File: CellValueServer.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取日期类型数据
 * 
 * @Author JueYue
 * @date 2013年11月26日
 * @param entity
 * @param value
 * @return
 */
private Date getDateData(ExcelImportEntity entity, String value) {
	if (StringUtils.isNotEmpty(entity.getFormat()) && StringUtils.isNotEmpty(value)) {
		SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
		try {
			return format.parse(value);
		} catch (ParseException e) {
			LOGGER.error("时间格式化失败,格式化:{},值:{}", entity.getFormat(), value);
			throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR);
		}
	}
	return null;
}
 
Example #19
Source File: ExcelImportServer.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取保存的真实路径
 * 
 * @param excelImportEntity
 * @param object
 * @return
 * @throws Exception
 */
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
	String url = "";
	if (excelImportEntity.getSaveUrl().equals("upload")) {
		if (excelImportEntity.getMethods() != null && excelImportEntity.getMethods().size() > 0) {
			object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
		}
		url = object.getClass().getName().split("\\.")[object.getClass().getName().split("\\.").length - 1];
		return excelImportEntity.getSaveUrl() + "/" + url.substring(0, url.lastIndexOf("Entity"));
	}
	return excelImportEntity.getSaveUrl();
}
 
Example #20
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param entity
 * @param object
 * @param value
 * @throws Exception
 */
public void setValues(ExcelImportEntity entity, Object object, Object value) throws Exception {
	if (entity.getMethods() != null) {
		setFieldBySomeMethod(entity.getMethods(), object, value);
	} else {
		entity.getMethod().invoke(object, value);
	}
}
 
Example #21
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
public void getExcelField(String targetId, Field field, ExcelImportEntity excelEntity, Excel excel, Class<?> pojoClass) throws Exception {
	excelEntity.setName(getExcelName(excel.name(), targetId));
	String fieldname = field.getName();
	excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass, field.getType()));
	if (StringUtils.isNotEmpty(excel.importFormat())) {
		excelEntity.setFormat(excel.importFormat());
	} else {
		excelEntity.setFormat(excel.format());
	}
}
 
Example #22
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isCollection(field.getType())) {
			// 集合对象设置属性
			ExcelCollectionParams collection = new ExcelCollectionParams();
			collection.setName(field.getName());
			Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
			ParameterizedType pt = (ParameterizedType) field.getGenericType();
			Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
			collection.setType(clz);
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
			collection.setExcelParams(temp);
			collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
			additionalCollectionName(collection);
			excelCollection.add(collection);
		} else if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
			getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods);
		}
	}
}
 
Example #23
Source File: CellValueServer.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取cell值
 * 
 * @param dataHanlder
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @return
 */
public Object getValue(IExcelDataHandler dataHanlder, Object object, SaxReadCellEntity cellEntity, Map<String, ExcelImportEntity> excelParams, String titleString) {
	ExcelImportEntity entity = excelParams.get(titleString);
	Method setMethod = entity.getMethods() != null && entity.getMethods().size() > 0 ? entity.getMethods().get(entity.getMethods().size() - 1) : entity.getMethod();
	Type[] ts = setMethod.getGenericParameterTypes();
	String xclass = ts[0].toString();
	Object result = cellEntity.getValue();
	result = hanlderSuffix(entity.getSuffix(), result);
	//update-begin-auhtor:taoyan date:20180807 for:多值替换
	result = replaceValue(entity.getReplace(), result,entity.isMultiReplace());
	//update-end-auhtor:taoyan date:20180807 for:多值替换
	result = hanlderValue(dataHanlder, object, result, titleString);
	return getValueByType(xclass, result, entity);
}
 
Example #24
Source File: CellValueServer.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取日期类型数据
 * 
 * @Author JEECG
 * @date 2013年11月26日
 * @param entity
 * @param value
 * @return
 */
private Date getDateData(ExcelImportEntity entity, String value) {
	if (StringUtils.isNotEmpty(entity.getFormat()) && StringUtils.isNotEmpty(value)) {
		SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
		try {
			return format.parse(value);
		} catch (ParseException e) {
			LOGGER.error("时间格式化失败,格式化:{},值:{}", entity.getFormat(), value);
			throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR);
		}
	}
	return null;
}
 
Example #25
Source File: ExcelImportServer.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取忽略的表头信息
 * @param excelParams
 * @param params
 */
private void ignoreHeaderHandler(Map<String, ExcelImportEntity> excelParams,ImportParams params){
	List<String> ignoreList = new ArrayList<>();
	for(String key:excelParams.keySet()){
		String temp = excelParams.get(key).getGroupName();
		if(temp!=null && temp.length()>0){
			ignoreList.add(temp);
		}
	}
	params.setIgnoreHeaderList(ignoreList);
}
 
Example #26
Source File: ExcelImportServer.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取保存的真实路径
 * 
 * @param excelImportEntity
 * @param object
 * @return
 * @throws Exception
 */
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
	String url = "";
	if (excelImportEntity.getSaveUrl().equals("upload")) {
		if (excelImportEntity.getMethods() != null && excelImportEntity.getMethods().size() > 0) {
			object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
		}
		url = object.getClass().getName().split("\\.")[object.getClass().getName().split("\\.").length - 1];
		return excelImportEntity.getSaveUrl() + "/" + url.substring(0, url.lastIndexOf("Entity"));
	}
	return excelImportEntity.getSaveUrl();
}
 
Example #27
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param entity
 * @param object
 * @param value
 * @throws Exception
 */
public void setValues(ExcelImportEntity entity, Object object, Object value) throws Exception {
	if (entity.getMethods() != null) {
		setFieldBySomeMethod(entity.getMethods(), object, value);
	} else {
		entity.getMethod().invoke(object, value);
	}
}
 
Example #28
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取需要导出的全部字段
 * 
 * 
 * @param exclusions
 * @param targetId
 *            目标ID
 * @param fields
 * @param excelCollection
 * @throws Exception
 */
public void getAllExcelField(String targetId, Field[] fields, Map<String, ExcelImportEntity> excelParams, List<ExcelCollectionParams> excelCollection, Class<?> pojoClass, List<Method> getMethods) throws Exception {
	ExcelImportEntity excelEntity = null;
	for (int i = 0; i < fields.length; i++) {
		Field field = fields[i];
		if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) {
			continue;
		}
		if (PoiPublicUtil.isCollection(field.getType())) {
			// 集合对象设置属性
			ExcelCollectionParams collection = new ExcelCollectionParams();
			collection.setName(field.getName());
			Map<String, ExcelImportEntity> temp = new HashMap<String, ExcelImportEntity>();
			ParameterizedType pt = (ParameterizedType) field.getGenericType();
			Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0];
			collection.setType(clz);
			getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null);
			collection.setExcelParams(temp);
			collection.setExcelName(field.getAnnotation(ExcelCollection.class).name());
			additionalCollectionName(collection);
			excelCollection.add(collection);
		} else if (PoiPublicUtil.isJavaClass(field)) {
			addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams);
		} else {
			List<Method> newMethods = new ArrayList<Method>();
			if (getMethods != null) {
				newMethods.addAll(getMethods);
			}
			newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass));
			getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, excelCollection, field.getType(), newMethods);
		}
	}
}
 
Example #29
Source File: CellValueServer.java    From jeasypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 根据返回类型获取返回值
 * 
 * @param xclass
 * @param result
 * @param entity
 * @return
 */
private Object getValueByType(String xclass, Object result, ExcelImportEntity entity) {
	try {
		if ("class java.util.Date".equals(xclass)) {
			return result;
		}
		if ("class java.lang.Boolean".equals(xclass) || "boolean".equals(xclass)) {
			return Boolean.valueOf(String.valueOf(result));
		}
		if ("class java.lang.Double".equals(xclass) || "double".equals(xclass)) {
			return Double.valueOf(String.valueOf(result));
		}
		if ("class java.lang.Long".equals(xclass) || "long".equals(xclass)) {
			return Long.valueOf(String.valueOf(result));
		}
		if ("class java.lang.Float".equals(xclass) || "float".equals(xclass)) {
			return Float.valueOf(String.valueOf(result));
		}
		if ("class java.lang.Integer".equals(xclass) || "int".equals(xclass)) {
			return Integer.valueOf(String.valueOf(result));
		}
		if ("class java.math.BigDecimal".equals(xclass)) {
			return new BigDecimal(String.valueOf(result));
		}
		if ("class java.lang.String".equals(xclass)) {
			// 针对String 类型,但是Excel获取的数据却不是String,比如Double类型,防止科学计数法
			if (result instanceof String) {
				return result;
			}
			// double类型防止科学计数法
			if (result instanceof Double) {
				return PoiPublicUtil.doubleToString((Double) result);
			}
			return String.valueOf(result);
		}
		return result;
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR);
	}
}
 
Example #30
Source File: CellValueServer.java    From easypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 根据返回类型获取返回值
 * 
 * @param xclass
 * @param result
 * @param entity 
 * @return
 */
private Object getValueByType(String xclass, Object result, ExcelImportEntity entity) {
    try {
        if ("class java.util.Date".equals(xclass)) {
            return result;
        }
        if ("class java.lang.Boolean".equals(xclass) || "boolean".equals(xclass)) {
            return Boolean.valueOf(String.valueOf(result));
        }
        if ("class java.lang.Double".equals(xclass) || "double".equals(xclass)) {
            return Double.valueOf(String.valueOf(result));
        }
        if ("class java.lang.Long".equals(xclass) || "long".equals(xclass)) {
            return Long.valueOf(String.valueOf(result));
        }
        if ("class java.lang.Float".equals(xclass) || "float".equals(xclass)) {
            return Float.valueOf(String.valueOf(result));
        }
        if ("class java.lang.Integer".equals(xclass) || "int".equals(xclass)) {
            return Integer.valueOf(String.valueOf(result));
        }
        if ("class java.math.BigDecimal".equals(xclass)) {
            return new BigDecimal(String.valueOf(result));
        }
        if ("class java.lang.String".equals(xclass)) {
            //针对String 类型,但是Excel获取的数据却不是String,比如Double类型,防止科学计数法
            if (result instanceof String) {
                return result;
            }
            // double类型防止科学计数法
            if (result instanceof Double) {
                return PoiPublicUtil.doubleToString((Double) result);
            }
            return String.valueOf(result);
        }
        return result;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR);
    }
}