org.jeecgframework.poi.excel.entity.sax.SaxReadCellEntity Java Examples

The following examples show how to use org.jeecgframework.poi.excel.entity.sax.SaxReadCellEntity. 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: SaxRowRead.java    From autopoi with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(int index, List<SaxReadCellEntity> datas) {
	try {
		if (datas == null || datas.size() == 0) {
			return;
		}
		// 标题行跳过
		if (index < params.getTitleRows()) {
			return;
		}
		// 表头行
		if (index < params.getTitleRows() + params.getHeadRows()) {
			addHeadData(datas);
		} else {
			addListData(datas);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		throw new ExcelImportException(e.getMessage());
	}
}
 
Example #2
Source File: SaxRowRead.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param exclusions
 * @param object
 * @param param
 * @param datas
 * @param titlemap
 * @param targetId
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param, List<SaxReadCellEntity> datas, Map<Integer, String> titlemap, String targetId, ImportParams params) throws Exception {
	Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), object.getClass()).invoke(object, new Object[] {});
	Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
	boolean isUsed = false;// 是否需要加上这个对象
	for (int i = 0; i < datas.size(); i++) {
		String titleString = (String) titlemap.get(i);
		if (param.getExcelParams().containsKey(titleString)) {
			saveFieldValue(params, entity, datas.get(i), param.getExcelParams(), titleString);
			isUsed = true;
		}
	}
	if (isUsed) {
		collection.add(entity);
	}
}
 
Example #3
Source File: SaxRowRead.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param exclusions
 * @param object
 * @param param
 * @param datas
 * @param titlemap
 * @param targetId
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param,
                             List<SaxReadCellEntity> datas, Map<Integer, String> titlemap,
                             String targetId, ImportParams params) throws Exception {
    Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(),
        object.getClass()).invoke(object, new Object[] {});
    Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
    boolean isUsed = false;// 是否需要加上这个对象
    for (int i = 0; i < datas.size(); i++) {
        String titleString = (String) titlemap.get(i);
        if (param.getExcelParams().containsKey(titleString)) {
            saveFieldValue(params, entity, datas.get(i), param.getExcelParams(), titleString);
            isUsed = true;
        }
    }
    if (isUsed) {
        collection.add(entity);
    }
}
 
Example #4
Source File: SaxRowRead.java    From easypoi with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(int index, List<SaxReadCellEntity> datas) {
    try {
        if (datas == null || datas.size() == 0) {
            return;
        }
        //标题行跳过
        if (index < params.getTitleRows()) {
            return;
        }
        //表头行
        if (index < params.getTitleRows() + params.getHeadRows()) {
            addHeadData(datas);
        } else {
            addListData(datas);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new ExcelImportException(e.getMessage());
    }
}
 
Example #5
Source File: SaxRowRead.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(int index, List<SaxReadCellEntity> datas) {
	try {
		if (datas == null || datas.size() == 0) {
			return;
		}
		// 标题行跳过
		if (index < params.getTitleRows()) {
			return;
		}
		// 表头行
		if (index < params.getTitleRows() + params.getHeadRows()) {
			addHeadData(datas);
		} else {
			addListData(datas);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		throw new ExcelImportException(e.getMessage());
	}
}
 
Example #6
Source File: SaxRowRead.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param exclusions
 * @param object
 * @param param
 * @param datas
 * @param titlemap
 * @param targetId
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param, List<SaxReadCellEntity> datas, Map<Integer, String> titlemap, String targetId, ImportParams params) throws Exception {
	Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), object.getClass()).invoke(object, new Object[] {});
	Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
	boolean isUsed = false;// 是否需要加上这个对象
	for (int i = 0; i < datas.size(); i++) {
		String titleString = (String) titlemap.get(i);
		if (param.getExcelParams().containsKey(titleString)) {
			saveFieldValue(params, entity, datas.get(i), param.getExcelParams(), titleString);
			isUsed = true;
		}
	}
	if (isUsed) {
		collection.add(entity);
	}
}
 
Example #7
Source File: SaxRowRead.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * put 表头数据
 * @param datas
 */
private void addHeadData(List<SaxReadCellEntity> datas) {
    for (int i = 0; i < datas.size(); i++) {
        if (StringUtils.isNotEmpty(String.valueOf(datas.get(i).getValue()))) {
            titlemap.put(i, String.valueOf(datas.get(i).getValue()));
        }
    }
}
 
Example #8
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 #9
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 #10
Source File: SaxRowRead.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * put 表头数据
 * 
 * @param datas
 */
private void addHeadData(List<SaxReadCellEntity> datas) {
	for (int i = 0; i < datas.size(); i++) {
		if (StringUtils.isNotEmpty(String.valueOf(datas.get(i).getValue()))) {
			titlemap.put(i, String.valueOf(datas.get(i).getValue()));
		}
	}
}
 
Example #11
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 #12
Source File: SaxRowRead.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * put 表头数据
 * 
 * @param datas
 */
private void addHeadData(List<SaxReadCellEntity> datas) {
	for (int i = 0; i < datas.size(); i++) {
		if (StringUtils.isNotEmpty(String.valueOf(datas.get(i).getValue()))) {
			titlemap.put(i, String.valueOf(datas.get(i).getValue()));
		}
	}
}
 
Example #13
Source File: SaxRowRead.java    From easypoi with Apache License 2.0 3 votes vote down vote up
/**
 * 设置值
 * @param params
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @throws Exception 
 */
private void saveFieldValue(ImportParams params, Object object, SaxReadCellEntity entity,
                            Map<String, ExcelImportEntity> excelParams, String titleString)
                                                                                           throws Exception {
    Object value = cellValueServer.getValue(params.getDataHanlder(), object, entity,
        excelParams, titleString);
    setValues(excelParams.get(titleString), object, value);
}
 
Example #14
Source File: SaxRowRead.java    From jeasypoi with Apache License 2.0 2 votes vote down vote up
/**
 * 设置值
 * 
 * @param params
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, SaxReadCellEntity entity, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception {
	Object value = cellValueServer.getValue(params.getDataHanlder(), object, entity, excelParams, titleString);
	setValues(excelParams.get(titleString), object, value);
}
 
Example #15
Source File: ISaxRowRead.java    From jeasypoi with Apache License 2.0 2 votes vote down vote up
/**
 * 解析数据
 * 
 * @param index
 * @param datas
 */
public void parse(int index, List<SaxReadCellEntity> datas);
 
Example #16
Source File: ISaxRowRead.java    From easypoi with Apache License 2.0 2 votes vote down vote up
/**
 * 解析数据
 * @param index
 * @param datas
 */
public void parse(int index, List<SaxReadCellEntity> datas);
 
Example #17
Source File: SaxRowRead.java    From autopoi with Apache License 2.0 2 votes vote down vote up
/**
 * 设置值
 * 
 * @param params
 * @param object
 * @param entity
 * @param excelParams
 * @param titleString
 * @throws Exception
 */
private void saveFieldValue(ImportParams params, Object object, SaxReadCellEntity entity, Map<String, ExcelImportEntity> excelParams, String titleString) throws Exception {
	Object value = cellValueServer.getValue(params.getDataHanlder(), object, entity, excelParams, titleString);
	setValues(excelParams.get(titleString), object, value);
}
 
Example #18
Source File: ISaxRowRead.java    From autopoi with Apache License 2.0 2 votes vote down vote up
/**
 * 解析数据
 * 
 * @param index
 * @param datas
 */
public void parse(int index, List<SaxReadCellEntity> datas);