org.jeecgframework.poi.excel.annotation.ExcelTarget Java Examples

The following examples show how to use org.jeecgframework.poi.excel.annotation.ExcelTarget. 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: ExcelExportOfTemplateUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/**
 * 往Sheet 填充正常数据
 * 
 * @param params
 * @param pojoClass
 * @param dataSet
 * @param workbook
 */
private static void addDataToSheet(TemplateExportParams params,
		Class<?> pojoClass, Collection<?> dataSet, Sheet sheet,
		Workbook workbook) throws Exception {
	Drawing patriarch = sheet.createDrawingPatriarch();
	List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
	// 得到所有字段
	Field fileds[] = ExcelPublicUtil.getClassFields(pojoClass);
	ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
	String targetId = null;
	if (etarget != null) {
		targetId = etarget.id();
	}
	getAllExcelField(targetId, fileds, excelParams, pojoClass, null);
	sortAllParams(excelParams);
	Iterator<?> its = dataSet.iterator();
	int index = sheet.getLastRowNum();
	while (its.hasNext()) {
		Object t = its.next();
		index += createCells(patriarch, index, t, excelParams, sheet,
				workbook);
	}
}
 
Example #2
Source File: ExcelExportOfTemplateUtil.java    From autopoi 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 #3
Source File: SaxRowRead.java    From autopoi 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 #4
Source File: ExcelEntityParse.java    From autopoi 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 #5
Source File: ExcelExportOfTemplateUtil.java    From jeasypoi 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 #6
Source File: SaxRowRead.java    From jeasypoi 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 #7
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 #8
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 #9
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 #10
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 #11
Source File: ExcelExportUtil.java    From jeewx with Apache License 2.0 5 votes vote down vote up
public static void createSheetInUserModel2File(HSSFWorkbook workbook,
		ExcelTitle entity, Class<?> pojoClass, Collection<?> dataSet) {
	try {
		Sheet sheet = workbook.createSheet(entity.getSheetName());
		//创建表格属性
		Map<String,HSSFCellStyle> styles = createStyles(workbook);
		Drawing patriarch = sheet.createDrawingPatriarch();
		List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
		// 得到所有字段
		Field fileds[] = ExcelPublicUtil.getClassFields(pojoClass);
		ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
		String targetId = null;
		if (etarget != null) {
			targetId = etarget.id();
		}
		getAllExcelField(targetId, fileds, excelParams, pojoClass, null);
		sortAllParams(excelParams);
		int index = 0;
		int feildWidth = getFieldWidth(excelParams);
		if (entity.getTitle() != null) {
			int i =  createHeaderRow(entity, sheet, workbook, feildWidth);
			sheet.createFreezePane(0, 2+i, 0, 2+i);
			index += i;
		} else {
			sheet.createFreezePane(0, 2, 0, 2);
		}
		createTitleRow(entity,sheet, workbook, index, excelParams);
		index += 2;
		setCellWith(excelParams, sheet);
		Iterator<?> its = dataSet.iterator();
		while (its.hasNext()) {
			Object t = its.next();
			index += createCells(patriarch,index, t, excelParams, sheet, workbook
					,styles);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}