org.jeecgframework.poi.util.PoiPublicUtil Java Examples

The following examples show how to use org.jeecgframework.poi.util.PoiPublicUtil. 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 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 #2
Source File: ExportBase.java    From easypoi with Apache License 2.0 6 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());
    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 #3
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 #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: ExcelMapParse.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JEECG
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list) throws Exception {
	XWPFTableRow currentRow = table.getRow(index);
	String[] params = parseCurrentRowGetParams(currentRow);
	table.removeRow(index);// 移除这一行
	int cellIndex = 0;// 创建完成对象一行好像多了一个cell
	for (Object obj : list) {
		currentRow = table.createRow();
		for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
			currentRow.getTableCells().get(cellIndex).setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
		for (; cellIndex < params.length; cellIndex++) {
			currentRow.createCell().setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
	}

}
 
Example #6
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 #7
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 #8
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 #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: ExcelMapParse.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list)
                                                                                       throws Exception {
    XWPFTableRow currentRow = table.getRow(index);
    String[] params = parseCurrentRowGetParams(currentRow);
    table.removeRow(index);// 移除这一行
    int cellIndex = 0;// 创建完成对象一行好像多了一个cell
    for (Object obj : list) {
        currentRow = table.createRow();
        for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
            currentRow
                .getTableCells()
                .get(cellIndex)
                .setText(
                    PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0)
                        .toString());
        }
        for (; cellIndex < params.length; cellIndex++) {
            currentRow.createCell().setText(
                PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0)
                    .toString());
        }
    }

}
 
Example #11
Source File: ParseWord07.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 添加图片
 * 
 * @Author JueYue
 * @date 2013-11-20
 * @param obj
 * @param currentRun
 * @throws Exception
 */
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception {
    Object[] isAndType = PoiPublicUtil.getIsAndType(obj);
    String picId;
    try {
        picId = currentRun.getParagraph().getDocument()
            .addPictureData((byte[]) isAndType[0], (Integer) isAndType[1]);
        ((MyXWPFDocument) currentRun.getParagraph().getDocument()).createPicture(currentRun,
            picId,
            currentRun.getParagraph().getDocument()
                .getNextPicNameNumber((Integer) isAndType[1]), obj.getWidth(), obj.getHeight());

    } catch (Exception e) {
        LOGGER.error(e.getMessage(),e);
    }

}
 
Example #12
Source File: ParseWord07.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 根据条件改变值
 * 
 * @param map
 * @Author JueYue
 * @date 2013-11-16
 */
private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText,
                          List<Integer> runIndex, Map<String, Object> map) throws Exception {
    Object obj = PoiPublicUtil.getRealValue(currentText, map);
    if (obj instanceof WordImageEntity) {// 如果是图片就设置为图片
        currentRun.setText("", 0);
        addAnImage((WordImageEntity) obj, currentRun);
    } else {
        currentText = obj.toString();
        currentRun.setText(currentText, 0);
    }
    for (int k = 0; k < runIndex.size(); k++) {
        paragraph.getRuns().get(runIndex.get(k)).setText("", 0);
    }
    runIndex.clear();
}
 
Example #13
Source File: ExcelMapParse.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 解析下一行,并且生成更多的行
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @param table
 * @param listobj2
 */
public static void parseNextRowAndAddRow(XWPFTable table, int index, List<Object> list) throws Exception {
	XWPFTableRow currentRow = table.getRow(index);
	String[] params = parseCurrentRowGetParams(currentRow);
	table.removeRow(index);// 移除这一行
	int cellIndex = 0;// 创建完成对象一行好像多了一个cell
	for (Object obj : list) {
		currentRow = table.createRow();
		for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) {
			currentRow.getTableCells().get(cellIndex).setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
		for (; cellIndex < params.length; cellIndex++) {
			currentRow.createCell().setText(PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0).toString());
		}
	}

}
 
Example #14
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 #15
Source File: ImportBaseService.java    From easypoi with Apache License 2.0 5 votes vote down vote up
public void saveThisExcel(ImportParams params, Class<?> pojoClass, boolean isXSSFWorkbook,
                          Workbook book) throws Exception {
    String path = PoiPublicUtil.getWebRootPath(getSaveExcelUrl(params, pojoClass));
    File savefile = new File(path);
    if (!savefile.exists()) {
        savefile.mkdirs();
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyMMddHHmmss");
    FileOutputStream fos = new FileOutputStream(path + "/" + format.format(new Date()) + "_"
                                                + Math.round(Math.random() * 100000)
                                                + (isXSSFWorkbook == true ? ".xlsx" : ".xls"));
    book.write(fos);
    fos.close();
}
 
Example #16
Source File: ExcelEntityParse.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 解析上一行并生成更多行
 * 
 * @param table
 * @param i
 * @param listobj
 */
public void parseNextRowAndAddRow(XWPFTable table, int index, ExcelListEntity entity) {
	checkExcelParams(entity);
	// 获取表头数据
	Map<String, Integer> titlemap = getTitleMap(table, index, entity.getHeadRows());
	try {
		// 得到所有字段
		Field fileds[] = PoiPublicUtil.getClassFields(entity.getClazz());
		ExcelTarget etarget = entity.getClazz().getAnnotation(ExcelTarget.class);
		String targetId = null;
		if (etarget != null) {
			targetId = etarget.value();
		}
		// 获取实体对象的导出数据
		List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
		getAllExcelField(null, targetId, fileds, excelParams, entity.getClazz(), null);
		// 根据表头进行筛选排序
		sortAndFilterExportField(excelParams, titlemap);
		short rowHeight = getRowHeight(excelParams);
		Iterator<?> its = entity.getList().iterator();
		while (its.hasNext()) {
			Object t = its.next();
			index += createCells(index, t, excelParams, table, rowHeight);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}
}
 
Example #17
Source File: ParseWord07.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 添加图片
 * 
 * @Author JueYue
 * @date 2013-11-20
 * @param obj
 * @param currentRun
 * @throws Exception
 */
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception {
	Object[] isAndType = PoiPublicUtil.getIsAndType(obj);
	String picId;
	try {
		picId = currentRun.getParagraph().getDocument().addPictureData((byte[]) isAndType[0], (Integer) isAndType[1]);
		((MyXWPFDocument) currentRun.getParagraph().getDocument()).createPicture(currentRun, picId, currentRun.getParagraph().getDocument().getNextPicNameNumber((Integer) isAndType[1]), obj.getWidth(), obj.getHeight());

	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}

}
 
Example #18
Source File: ParseWord07.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 根据条件改变值
 * 
 * @param map
 * @Author JueYue
 * @date 2013-11-16
 */
private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText, List<Integer> runIndex, Map<String, Object> map) throws Exception {
	Object obj = PoiPublicUtil.getRealValue(currentText, map);
	if (obj instanceof WordImageEntity) {// 如果是图片就设置为图片
		currentRun.setText("", 0);
		addAnImage((WordImageEntity) obj, currentRun);
	} else {
		currentText = obj.toString();
		currentRun.setText(currentText, 0);
	}
	for (int k = 0; k < runIndex.size(); k++) {
		paragraph.getRuns().get(runIndex.get(k)).setText("", 0);
	}
	runIndex.clear();
}
 
Example #19
Source File: ParseWord07.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是不是迭代输出
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @return
 * @throws Exception
 */
private Object checkThisTableIsNeedIterator(XWPFTableCell cell, Map<String, Object> map) throws Exception {
	String text = cell.getText().trim();
	// 判断是不是迭代输出
	if (text.startsWith("{{") && text.endsWith("}}") && text.indexOf("in ") != -1) {
		return PoiPublicUtil.getRealValue(text.replace("in ", "").trim(), map);
	}
	return null;
}
 
Example #20
Source File: ExcelExportBase.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取图片类型,设置图片插入类型
 * 
 * @param value
 * @return
 * @Author JueYue
 * @date 2013年11月25日
 */
public int getImageType(byte[] value) {
    String type = PoiPublicUtil.getFileExtendName(value);
    if (type.equalsIgnoreCase("JPG")) {
        return Workbook.PICTURE_TYPE_JPEG;
    } else if (type.equalsIgnoreCase("PNG")) {
        return Workbook.PICTURE_TYPE_PNG;
    }
    return Workbook.PICTURE_TYPE_JPEG;
}
 
Example #21
Source File: ExcelExportOfTemplateUtil.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 往Sheet 填充正常数据,根据表头信息 使用导入的部分逻辑,坐对象映射
 * 
 * @param teplateParams
 * @param pojoClass
 * @param dataSet
 * @param workbook
 */
private void addDataToSheet(Class<?> pojoClass, Collection<?> dataSet, Sheet sheet,
                            Workbook workbook) throws Exception {

    if (workbook instanceof XSSFWorkbook) {
        super.type = ExcelType.XSSF;
    }
    // 获取表头数据
    Map<String, Integer> titlemap = getTitleMap(sheet);
    Drawing patriarch = sheet.createDrawingPatriarch();
    // 得到所有字段
    Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
    ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
    String targetId = null;
    if (etarget != null) {
        targetId = etarget.value();
    }
    // 获取实体对象的导出数据
    List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
    getAllExcelField(null, targetId, fileds, excelParams, pojoClass, null);
    // 根据表头进行筛选排序
    sortAndFilterExportField(excelParams, titlemap);
    short rowHeight = getRowHeight(excelParams);
    int index = teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(), titleHeight = index;
    //下移数据,模拟插入
    sheet.shiftRows(teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(),
        sheet.getLastRowNum(), getShiftRows(dataSet, excelParams), true, true);
    if (excelParams.size() == 0) {
        return;
    }
    Iterator<?> its = dataSet.iterator();
    while (its.hasNext()) {
        Object t = its.next();
        index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight);
    }
    // 合并同类项
    mergeCells(sheet, excelParams, titleHeight);
}
 
Example #22
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 #23
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 #24
Source File: ExcelTempletController.java    From jeecg with Apache License 2.0 5 votes vote down vote up
@Override
public void setMapValue(Map<String, Object> map, String originKey, Object value) {
	if (value instanceof Double) {
		map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
	} else {
		map.put(getRealKey(originKey), value.toString());
	}
}
 
Example #25
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 #26
Source File: SaxRowRead.java    From easypoi with Apache License 2.0 5 votes vote down vote up
private void initParams(Class<?> pojoClass, ImportParams params) {
    try {

        Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
        ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
        if (etarget != null) {
            targetId = etarget.value();
        }
        getAllExcelField(targetId, fileds, excelParams, excelCollection, pojoClass, null);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new ExcelImportException(e.getMessage());
    }

}
 
Example #27
Source File: ExcelEntityParse.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 解析上一行并生成更多行
 * 
 * @param table
 * @param i
 * @param listobj
 */
public void parseNextRowAndAddRow(XWPFTable table, int index, ExcelListEntity entity) {
    checkExcelParams(entity);
    // 获取表头数据
    Map<String, Integer> titlemap = getTitleMap(table, index, entity.getHeadRows());
    try {
        // 得到所有字段
        Field fileds[] = PoiPublicUtil.getClassFields(entity.getClazz());
        ExcelTarget etarget = entity.getClazz().getAnnotation(ExcelTarget.class);
        String targetId = null;
        if (etarget != null) {
            targetId = etarget.value();
        }
        // 获取实体对象的导出数据
        List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
        getAllExcelField(null, targetId, fileds, excelParams, entity.getClazz(), null);
        // 根据表头进行筛选排序
        sortAndFilterExportField(excelParams, titlemap);
        short rowHeight = getRowHeight(excelParams);
        Iterator<?> its = entity.getList().iterator();
        while (its.hasNext()) {
            Object t = its.next();
            index += createCells(index, t, excelParams, table, rowHeight);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
Example #28
Source File: ParseWord07.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是不是迭代输出
 * 
 * @Author JueYue
 * @date 2013-11-18
 * @return
 * @throws Exception
 */
private Object checkThisTableIsNeedIterator(XWPFTableCell cell, Map<String, Object> map)
                                                                                        throws Exception {
    String text = cell.getText().trim();
    // 判断是不是迭代输出
    if (text.startsWith("{{") && text.endsWith("}}") && text.indexOf("in ") != -1) {
        return PoiPublicUtil.getRealValue(text.replace("in ", "").trim(), map);
    }
    return null;
}
 
Example #29
Source File: CommonUtils.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
public static String uploadOnlineImage(byte[] data,String basePath,String bizPath,String uploadType){
    String dbPath = null;
    String fileName = "image" + Math.round(Math.random() * 100000000000L);
    fileName += "." + PoiPublicUtil.getFileExtendName(data);
    try {
        if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
            File file = new File(basePath + File.separator + bizPath + File.separator );
            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(data, savefile);
            dbPath = bizPath + File.separator + fileName;
        }else {
            InputStream in = new ByteArrayInputStream(data);
            String relativePath = bizPath+"/"+fileName;
            if(CommonConstant.UPLOAD_TYPE_MINIO.equals(uploadType)){
                dbPath = MinioUtil.upload(in,relativePath);
            }else if(CommonConstant.UPLOAD_TYPE_OSS.equals(uploadType)){
                dbPath = OssBootUtil.upload(in,relativePath);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dbPath;
}
 
Example #30
Source File: ParseWord07.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是不是迭代输出
 * 
 * @Author JEECG
 * @date 2013-11-18
 * @return
 * @throws Exception
 */
private Object checkThisTableIsNeedIterator(XWPFTableCell cell, Map<String, Object> map) throws Exception {
	String text = cell.getText().trim();
	// 判断是不是迭代输出
	if (text.startsWith("{{") && text.endsWith("}}") && text.indexOf("in ") != -1) {
		return PoiPublicUtil.getRealValue(text.replace("in ", "").trim(), map);
	}
	return null;
}