Java Code Examples for org.jeecgframework.poi.exception.excel.enums.ExcelImportEnum#GET_VALUE_ERROR

The following examples show how to use org.jeecgframework.poi.exception.excel.enums.ExcelImportEnum#GET_VALUE_ERROR . 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 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 2
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 3
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 4
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 5
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);
    }
}