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

The following examples show how to use org.jeecgframework.poi.excel.entity.params.ExcelCollectionParams. 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: ExcelImportServer.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param object
 * @param param
 * @param row
 * @param titlemap
 * @param targetId
 * @param pictures
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param, Row row, Map<Integer, String> titlemap, String targetId, Map<String, PictureData> pictures, ImportParams params) throws Exception {
	Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), object.getClass()).invoke(object, new Object[] {});
	Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
	String picId;
	boolean isUsed = false;// 是否需要加上这个对象
	for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
		Cell cell = row.getCell(i);
		String titleString = (String) titlemap.get(i);
		if (param.getExcelParams().containsKey(titleString)) {
			if (param.getExcelParams().get(titleString).getType() == 2) {
				picId = row.getRowNum() + "_" + i;
				saveImage(object, picId, param.getExcelParams(), titleString, pictures, params);
			} else {
				saveFieldValue(params, entity, cell, param.getExcelParams(), titleString, row);
			}
			isUsed = true;
		}
	}
	if (isUsed) {
		collection.add(entity);
	}
}
 
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: ExcelImportServer.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param exclusions
 * @param object
 * @param param
 * @param row
 * @param titlemap
 * @param targetId
 * @param pictures
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param, Row row, Map<Integer, String> titlemap, String targetId, Map<String, PictureData> pictures, ImportParams params) throws Exception {
	Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), object.getClass()).invoke(object, new Object[] {});
	Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
	String picId;
	boolean isUsed = false;// 是否需要加上这个对象
	for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
		Cell cell = row.getCell(i);
		String titleString = (String) titlemap.get(i);
		if (param.getExcelParams().containsKey(titleString)) {
			if (param.getExcelParams().get(titleString).getType() == 2) {
				picId = row.getRowNum() + "_" + i;
				saveImage(object, picId, param.getExcelParams(), titleString, pictures, params);
			} else {
				saveFieldValue(params, entity, cell, param.getExcelParams(), titleString, row);
			}
			isUsed = true;
		}
	}
	if (isUsed) {
		collection.add(entity);
	}
}
 
Example #4
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 #5
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 #6
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 #7
Source File: ImportBaseService.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 追加集合名称到前面
 * 
 * @param collection
 */
private void additionalCollectionName(ExcelCollectionParams collection) {
	Set<String> keys = new HashSet<String>();
	keys.addAll(collection.getExcelParams().keySet());
	for (String key : keys) {
		collection.getExcelParams().put(collection.getExcelName() + "_" + key, collection.getExcelParams().get(key));
		collection.getExcelParams().remove(key);
	}
}
 
Example #8
Source File: ExcelImportServer.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取这个名称对应的集合信息
 * 
 * @param excelCollection
 * @param collectionName
 * @return
 */
private ExcelCollectionParams getCollectionParams(List<ExcelCollectionParams> excelCollection, String collectionName) {
	for (ExcelCollectionParams excelCollectionParams : excelCollection) {
		if (collectionName.equals(excelCollectionParams.getExcelName())) {
			return excelCollectionParams;
		}
	}
	return null;
}
 
Example #9
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 #10
Source File: ImportBaseService.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 追加集合名称到前面
 * 
 * @param collection
 */
private void additionalCollectionName(ExcelCollectionParams collection) {
	Set<String> keys = new HashSet<String>();
	keys.addAll(collection.getExcelParams().keySet());
	for (String key : keys) {
		collection.getExcelParams().put(collection.getExcelName() + "_" + key, collection.getExcelParams().get(key));
		collection.getExcelParams().remove(key);
	}
}
 
Example #11
Source File: ExcelImportServer.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取这个名称对应的集合信息
 * 
 * @param excelCollection
 * @param collectionName
 * @return
 */
private ExcelCollectionParams getCollectionParams(List<ExcelCollectionParams> excelCollection, String collectionName) {
	for (ExcelCollectionParams excelCollectionParams : excelCollection) {
		if (collectionName.equals(excelCollectionParams.getExcelName())) {
			return excelCollectionParams;
		}
	}
	return null;
}
 
Example #12
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 #13
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 追加集合名称到前面
 * @param collection
 */
private void additionalCollectionName(ExcelCollectionParams collection) {
    Set<String> keys = new HashSet<String>();
    keys.addAll(collection.getExcelParams().keySet());
    for (String key : keys) {
        collection.getExcelParams().put(collection.getExcelName() + "_" + key,
            collection.getExcelParams().get(key));
        collection.getExcelParams().remove(key);
    }
}
 
Example #14
Source File: ExcelImportServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/***
 * 向List里面继续添加元素
 * 
 * @param exclusions
 * @param object
 * @param param
 * @param row
 * @param titlemap
 * @param targetId
 * @param pictures
 * @param params
 */
private void addListContinue(Object object, ExcelCollectionParams param, Row row,
                             Map<Integer, String> titlemap, String targetId,
                             Map<String, PictureData> pictures, ImportParams params)
                                                                                    throws Exception {
    Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(),
        object.getClass()).invoke(object, new Object[] {});
    Object entity = PoiPublicUtil.createObject(param.getType(), targetId);
    String picId;
    boolean isUsed = false;// 是否需要加上这个对象
    for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
        Cell cell = row.getCell(i);
        String titleString = (String) titlemap.get(i);
        if (param.getExcelParams().containsKey(titleString)) {
            if (param.getExcelParams().get(titleString).getType() == 2) {
                picId = row.getRowNum() + "_" + i;
                saveImage(object, picId, param.getExcelParams(), titleString, pictures, params);
            } else {
                saveFieldValue(params, entity, cell, param.getExcelParams(), titleString, row);
            }
            isUsed = true;
        }
    }
    if (isUsed) {
        collection.add(entity);
    }
}
 
Example #15
Source File: ExcelImportServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取表格字段列名对应信息
 * @param rows
 * @param params
 * @param excelCollection
 * @return
 */
private Map<Integer, String> getTitleMap(Iterator<Row> rows, ImportParams params,
                                         List<ExcelCollectionParams> excelCollection) {
    Map<Integer, String> titlemap = new HashMap<Integer, String>();
    Iterator<Cell> cellTitle;
    String collectionName = null;
    ExcelCollectionParams collectionParams = null;
    Row row = null;
    for (int j = 0; j < params.getHeadRows(); j++) {
        row = rows.next();
        if(row == null){
            continue;
        }
        cellTitle = row.cellIterator();
        while (cellTitle.hasNext()) {
            Cell cell = cellTitle.next();
            String value = getKeyValue(cell);
            int i = cell.getColumnIndex();
            //用以支持重名导入
            if (StringUtils.isNotEmpty(value)) {
                if (titlemap.containsKey(i)) {
                    collectionName = titlemap.get(i);
                    collectionParams = getCollectionParams(excelCollection, collectionName);
                    titlemap.put(i, collectionName + "_" + value);
                } else if (StringUtils.isNotEmpty(collectionName)
                           && collectionParams.getExcelParams().containsKey(
                               collectionName + "_" + value)) {
                    titlemap.put(i, collectionName + "_" + value);
                } else {
                    collectionName = null;
                    collectionParams = null;
                }
                if (StringUtils.isEmpty(collectionName)) {
                    titlemap.put(i, value);
                }
            }
        }
    }
    return titlemap;
}
 
Example #16
Source File: ExcelImportServer.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取这个名称对应的集合信息
 * @param excelCollection 
 * @param collectionName
 * @return
 */
private ExcelCollectionParams getCollectionParams(List<ExcelCollectionParams> excelCollection,
                                                  String collectionName) {
    for (ExcelCollectionParams excelCollectionParams : excelCollection) {
        if (collectionName.equals(excelCollectionParams.getExcelName())) {
            return excelCollectionParams;
        }
    }
    return null;
}