org.jeecgframework.poi.exception.excel.ExcelExportException Java Examples

The following examples show how to use org.jeecgframework.poi.exception.excel.ExcelExportException. 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: PoiElUtil.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 是不是真
 * 
 * @param keys
 * @param map
 * @return
 * @throws Exception
 */
private static Boolean isTrue(String[] keys, Map<String, Object> map) throws Exception {
	if (keys.length == 0) {
		String constant = null;
		if ((constant = isConstant(keys[0])) != null) {
			return Boolean.valueOf(constant);
		}
		return Boolean.valueOf(PoiPublicUtil.getParamsValue(keys[0], map).toString());
	}
	if (keys.length == 3) {
		Object first = eval(keys[0], map);
		Object second = eval(keys[2], map);
		return PoiFunctionUtil.isTrue(first, keys[1], second);
	}
	throw new ExcelExportException("判断参数不对");
}
 
Example #2
Source File: PoiFunctionUtil.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是不是成功
 * 
 * @param first
 * @param operator
 * @param second
 * @return
 */
public static boolean isTrue(Object first, String operator, Object second) {
	if (">".endsWith(operator)) {
		return isGt(first, second);
	} else if ("<".endsWith(operator)) {
		return isGt(second, first);
	} else if ("==".endsWith(operator)) {
		if (first != null && second != null) {
			return first.equals(second);
		}
		return first == second;
	} else if ("!=".endsWith(operator)) {
		if (first != null && second != null) {
			return !first.equals(second);
		}
		return first != second;
	} else {
		throw new ExcelExportException("占不支持改操作符");
	}
}
 
Example #3
Source File: PoiElUtil.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 是不是真
 * 
 * @param keys
 * @param map
 * @return
 * @throws Exception
 */
private static Boolean isTrue(String[] keys, Map<String, Object> map) throws Exception {
	if (keys.length == 0) {
		String constant = null;
		if ((constant = isConstant(keys[0])) != null) {
			return Boolean.valueOf(constant);
		}
		return Boolean.valueOf(PoiPublicUtil.getParamsValue(keys[0], map).toString());
	}
	if (keys.length == 3) {
		Object first = eval(keys[0], map);
		Object second = eval(keys[2], map);
		return PoiFunctionUtil.isTrue(first, keys[1], second);
	}
	throw new ExcelExportException("判断参数不对");
}
 
Example #4
Source File: PoiFunctionUtil.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是不是成功
 * 
 * @param first
 * @param operator
 * @param second
 * @return
 */
public static boolean isTrue(Object first, String operator, Object second) {
	if (">".endsWith(operator)) {
		return isGt(first, second);
	} else if ("<".endsWith(operator)) {
		return isGt(second, first);
	} else if ("==".endsWith(operator)) {
		if (first != null && second != null) {
			return first.equals(second);
		}
		return first == second;
	} else if ("!=".endsWith(operator)) {
		if (first != null && second != null) {
			return !first.equals(second);
		}
		return first != second;
	} else {
		throw new ExcelExportException("占不支持改操作符");
	}
}
 
Example #5
Source File: PoiElUtil.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 是不是真
 * @param keys
 * @param map
 * @return
 * @throws Exception
 */
private static Boolean isTrue(String[] keys, Map<String, Object> map) throws Exception {
    if (keys.length == 0) {
        String constant = null;
        if ((constant = isConstant(keys[0])) != null) {
            return Boolean.valueOf(constant);
        }
        return Boolean.valueOf(PoiPublicUtil.getParamsValue(keys[0], map).toString());
    }
    if (keys.length == 3) {
        Object first = eval(keys[0], map);
        Object second = eval(keys[2], map);
        return PoiFunctionUtil.isTrue(first, keys[1], second);
    }
    throw new ExcelExportException("判断参数不对");
}
 
Example #6
Source File: PoiFunctionUtil.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是不是成功
 * @param first
 * @param operator
 * @param second
 * @return
 */
public static boolean isTrue(Object first, String operator, Object second) {
    if (">".endsWith(operator)) {
        return isGt(first, second);
    } else if ("<".endsWith(operator)) {
        return isGt(second, first);
    } else if ("==".endsWith(operator)) {
        if (first != null && second != null) {
            return first.equals(second);
        }
        return first == second;
    } else if ("!=".endsWith(operator)) {
        if (first != null && second != null) {
            return !first.equals(second);
        }
        return first != second;
    } else {
        throw new ExcelExportException("占不支持改操作符");
    }
}
 
Example #7
Source File: ExcelExportOfTemplateUtil.java    From autopoi with Apache License 2.0 5 votes vote down vote up
public Workbook createExcleByTemplate(TemplateExportParams params, Class<?> pojoClass, Collection<?> dataSet, Map<String, Object> map) {
	// step 1. 判断模板的地址
	if (params == null || map == null || StringUtils.isEmpty(params.getTemplateUrl())) {
		throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR);
	}
	Workbook wb = null;
	// step 2. 判断模板的Excel类型,解析模板
	try {
		this.teplateParams = params;
		wb = getCloneWorkBook();
		// 创建表格样式
		setExcelExportStyler((IExcelExportStyler) teplateParams.getStyle().getConstructor(Workbook.class).newInstance(wb));
		// step 3. 解析模板
		for (int i = 0, le = params.isScanAllsheet() ? wb.getNumberOfSheets() : params.getSheetNum().length; i < le; i++) {
			if (params.getSheetName() != null && params.getSheetName().length > i && StringUtils.isNotEmpty(params.getSheetName()[i])) {
				wb.setSheetName(i, params.getSheetName()[i]);
			}
			tempCreateCellSet.clear();
			parseTemplate(wb.getSheetAt(i), map);
		}
		if (dataSet != null) {
			// step 4. 正常的数据填充
			dataHanlder = params.getDataHanlder();
			if (dataHanlder != null) {
				needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields());
			}
			addDataToSheet(pojoClass, dataSet, wb.getSheetAt(params.getDataSheetNum()), wb);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		return null;
	}
	return wb;
}
 
Example #8
Source File: PoiMergeCellUtil.java    From autopoi with Apache License 2.0 5 votes vote down vote up
/**
 * 纵向合并相同内容的单元格
 * 
 * @param sheet
 * @param startRow
 *            开始行
 * @param columns
 *            需要处理的列
 */
public static void mergeCells(Sheet sheet, int startRow, Integer... columns) {
	if (columns == null) {
		throw new ExcelExportException("至少需要处理1列");
	}
	Map<Integer, int[]> mergeMap = new HashMap<Integer, int[]>();
	for (int i = 0; i < columns.length; i++) {
		mergeMap.put(columns[i], null);
	}
	mergeCells(sheet, mergeMap, startRow, sheet.getLastRowNum());
}
 
Example #9
Source File: ExcelExportOfTemplateUtil.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
public Workbook createExcleByTemplate(TemplateExportParams params, Class<?> pojoClass, Collection<?> dataSet, Map<String, Object> map) {
	// step 1. 判断模板的地址
	if (params == null || map == null || StringUtils.isEmpty(params.getTemplateUrl())) {
		throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR);
	}
	Workbook wb = null;
	// step 2. 判断模板的Excel类型,解析模板
	try {
		this.teplateParams = params;
		wb = getCloneWorkBook();
		// 创建表格样式
		setExcelExportStyler((IExcelExportStyler) teplateParams.getStyle().getConstructor(Workbook.class).newInstance(wb));
		// step 3. 解析模板
		for (int i = 0, le = params.isScanAllsheet() ? wb.getNumberOfSheets() : params.getSheetNum().length; i < le; i++) {
			if (params.getSheetName() != null && params.getSheetName().length > i && StringUtils.isNotEmpty(params.getSheetName()[i])) {
				wb.setSheetName(i, params.getSheetName()[i]);
			}
			tempCreateCellSet.clear();
			parseTemplate(wb.getSheetAt(i), map);
		}
		if (dataSet != null) {
			// step 4. 正常的数据填充
			dataHanlder = params.getDataHanlder();
			if (dataHanlder != null) {
				needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields());
			}
			addDataToSheet(pojoClass, dataSet, wb.getSheetAt(params.getDataSheetNum()), wb);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
		return null;
	}
	return wb;
}
 
Example #10
Source File: PoiMergeCellUtil.java    From jeasypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 纵向合并相同内容的单元格
 * 
 * @param sheet
 * @param startRow
 *            开始行
 * @param columns
 *            需要处理的列
 */
public static void mergeCells(Sheet sheet, int startRow, Integer... columns) {
	if (columns == null) {
		throw new ExcelExportException("至少需要处理1列");
	}
	Map<Integer, int[]> mergeMap = new HashMap<Integer, int[]>();
	for (int i = 0; i < columns.length; i++) {
		mergeMap.put(columns[i], null);
	}
	mergeCells(sheet, mergeMap, startRow, sheet.getLastRowNum());
}
 
Example #11
Source File: ExcelExportOfTemplateUtil.java    From easypoi with Apache License 2.0 5 votes vote down vote up
public Workbook createExcleByTemplate(TemplateExportParams params, Class<?> pojoClass,
                                      Collection<?> dataSet, Map<String, Object> map) {
    // step 1. 判断模板的地址
    if (params == null || map == null || StringUtils.isEmpty(params.getTemplateUrl())) {
        throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR);
    }
    Workbook wb = null;
    // step 2. 判断模板的Excel类型,解析模板
    try {
        this.teplateParams = params;
        wb = getCloneWorkBook();
        // 创建表格样式
        setExcelExportStyler((IExcelExportStyler) teplateParams.getStyle()
            .getConstructor(Workbook.class).newInstance(wb));
        // step 3. 解析模板
        for (int i = 0, le = params.isScanAllsheet() ? wb.getNumberOfSheets() : params
            .getSheetNum().length; i < le; i++) {
            if (params.getSheetName() != null && params.getSheetName().length > i
                && StringUtils.isNotEmpty(params.getSheetName()[i])) {
                wb.setSheetName(i, params.getSheetName()[i]);
            }
            tempCreateCellSet.clear();
            parseTemplate(wb.getSheetAt(i), map);
        }
        if (dataSet != null) {
            // step 4. 正常的数据填充
            dataHanlder = params.getDataHanlder();
            if (dataHanlder != null) {
                needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields());
            }
            addDataToSheet(pojoClass, dataSet, wb.getSheetAt(params.getDataSheetNum()), wb);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
    return wb;
}
 
Example #12
Source File: PoiMergeCellUtil.java    From easypoi with Apache License 2.0 5 votes vote down vote up
/**
 * 纵向合并相同内容的单元格
 * 
 * @param sheet
 * @param startRow 开始行
 * @param columns 需要处理的列
 */
public static void mergeCells(Sheet sheet, int startRow, Integer... columns) {
    if (columns == null) {
        throw new ExcelExportException("至少需要处理1列");
    }
    Map<Integer, int[]> mergeMap = new HashMap<Integer, int[]>();
    for (int i = 0; i < columns.length; i++) {
        mergeMap.put(columns[i], null);
    }
    mergeCells(sheet, mergeMap, startRow, sheet.getLastRowNum());
}
 
Example #13
Source File: ExcelExportOfTemplateUtil.java    From autopoi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取迭代的数据的值
 * 
 * @param cell
 * @param name
 * @return
 */
private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) {
	List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>();
	cell.setCellValue("");
	if (name.contains(END_STR)) {
		columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY).trim(), cell.getCellStyle(), cell.getRow().getHeight()));
		return columns;
	}
	columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow().getHeight()));
	int index = cell.getColumnIndex();
	Cell tempCell;
	while (true) {
		tempCell = cell.getRow().getCell(++index);
		if (tempCell == null) {
			break;
		}
		String cellStringString;
		try {// 允许为空,单表示已经完结了,因为可能被删除了
			cellStringString = tempCell.getStringCellValue();
			if (StringUtils.isBlank(cellStringString)) {
				break;
			}
		} catch (Exception e) {
			throw new ExcelExportException("for each 当中存在空字符串,请检查模板");
		}
		// 把读取过的cell 置为空
		tempCell.setCellValue("");
		if (cellStringString.contains(END_STR)) {
			columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""), tempCell.getCellStyle(), tempCell.getRow().getHeight()));
			break;
		} else {
			if (cellStringString.trim().contains(teplateParams.getTempParams())) {
				columns.add(new ExcelTemplateParams(cellStringString.trim(), tempCell.getCellStyle(), tempCell.getRow().getHeight()));
			} else {
				// 最后一行被删除了
				break;
			}
		}

	}
	return columns;
}
 
Example #14
Source File: ExcelExportOfTemplateUtil.java    From jeasypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取迭代的数据的值
 * 
 * @param cell
 * @param name
 * @return
 */
private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) {
	List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>();
	cell.setCellValue("");
	if (name.contains(END_STR)) {
		columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY).trim(), cell.getCellStyle(), cell.getRow().getHeight()));
		return columns;
	}
	columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow().getHeight()));
	int index = cell.getColumnIndex();
	Cell tempCell;
	while (true) {
		tempCell = cell.getRow().getCell(++index);
		if (tempCell == null) {
			break;
		}
		String cellStringString;
		try {// 允许为空,单表示已经完结了,因为可能被删除了
			cellStringString = tempCell.getStringCellValue();
			if (StringUtils.isBlank(cellStringString)) {
				break;
			}
		} catch (Exception e) {
			throw new ExcelExportException("for each 当中存在空字符串,请检查模板");
		}
		// 把读取过的cell 置为空
		tempCell.setCellValue("");
		if (cellStringString.contains(END_STR)) {
			columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""), tempCell.getCellStyle(), tempCell.getRow().getHeight()));
			break;
		} else {
			if (cellStringString.trim().contains(teplateParams.getTempParams())) {
				columns.add(new ExcelTemplateParams(cellStringString.trim(), tempCell.getCellStyle(), tempCell.getRow().getHeight()));
			} else {
				// 最后一行被删除了
				break;
			}
		}

	}
	return columns;
}
 
Example #15
Source File: ExcelExportOfTemplateUtil.java    From easypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取迭代的数据的值
 * @param cell
 * @param name
 * @return
 */
private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) {
    List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>();
    cell.setCellValue("");
    if (name.contains(END_STR)) {
        columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY).trim(), cell
            .getCellStyle(), cell.getRow().getHeight()));
        return columns;
    }
    columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow()
        .getHeight()));
    int index = cell.getColumnIndex();
    Cell tempCell;
    while (true) {
        tempCell = cell.getRow().getCell(++index);
        if (tempCell == null) {
            break;
        }
        String cellStringString;
        try {//允许为空,单表示已经完结了,因为可能被删除了
            cellStringString = tempCell.getStringCellValue();
            if (StringUtils.isBlank(cellStringString)) {
                break;
            }
        } catch (Exception e) {
            throw new ExcelExportException("for each 当中存在空字符串,请检查模板");
        }
        //把读取过的cell 置为空
        tempCell.setCellValue("");
        if (cellStringString.contains(END_STR)) {
            columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""),
                tempCell.getCellStyle(), tempCell.getRow().getHeight()));
            break;
        } else {
            if (cellStringString.trim().contains(teplateParams.getTempParams())) {
                columns.add(new ExcelTemplateParams(cellStringString.trim(), tempCell
                    .getCellStyle(), tempCell.getRow().getHeight()));
            } else {
                //最后一行被删除了
                break;
            }
        }

    }
    return columns;
}