org.apache.poi.hssf.usermodel.HSSFDataValidation Java Examples

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFDataValidation. 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: GenerateDoc.java    From danyuan-application with Apache License 2.0 6 votes vote down vote up
private static void setDataValidationList(int j, int k, int l, int m, String data, HSSFSheet sheet) {
	// 设置下拉列表的内容
	String[] textlist = data.split(",");
	// 加载下拉列表内容
	DVConstraint constraint = DVConstraint.createExplicitListConstraint(textlist);
	// 设置数据有效性加载在哪个单元格上。
	
	// 四个参数分别是:起始行、终止行、起始列、终止列
	CellRangeAddressList regions = new CellRangeAddressList(j, k, l, m);
	/*   CellRangeAddressList regions = new CellRangeAddressList(
	      6,5, 6,5);*/
	// 数据有效性对象
	HSSFDataValidation data_validation_list = new HSSFDataValidation(regions, constraint);
	data_validation_list.setSuppressDropDownArrow(false);
	sheet.addValidationData(data_validation_list);
}
 
Example #2
Source File: ExcelUtil.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 设置单元格上提示
 * 
 * @param sheet 要设置的sheet.
 * @param promptTitle 标题
 * @param promptContent 内容
 * @param firstRow 开始行
 * @param endRow 结束行
 * @param firstCol 开始列
 * @param endCol 结束列
 * @return 设置好的sheet.
 */
public static Sheet setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
        int firstCol, int endCol)
{
    // 构造constraint对象
    DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
    // 四个参数分别是:起始行、终止行、起始列、终止列
    CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
    // 数据有效性对象
    HSSFDataValidation dataValidationView = new HSSFDataValidation(regions, constraint);
    dataValidationView.createPromptBox(promptTitle, promptContent);
    sheet.addValidationData(dataValidationView);
    return sheet;
}
 
Example #3
Source File: ExcelUtil.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 设置某些列的值只能输入预制的数据,显示下拉框.
 * 
 * @param sheet 要设置的sheet.
 * @param textlist 下拉框显示的内容
 * @param firstRow 开始行
 * @param endRow 结束行
 * @param firstCol 开始列
 * @param endCol 结束列
 * @return 设置好的sheet.
 */
public static Sheet setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol,
        int endCol)
{
    // 加载下拉列表内容
    DVConstraint constraint = DVConstraint.createExplicitListConstraint(textlist);
    // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
    CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
    // 数据有效性对象
    HSSFDataValidation dataValidationList = new HSSFDataValidation(regions, constraint);
    sheet.addValidationData(dataValidationList);
    return sheet;
}
 
Example #4
Source File: ExcelUtil.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 设置单元格上提示
 * 
 * @param sheet 要设置的sheet.
 * @param promptTitle 标题
 * @param promptContent 内容
 * @param firstRow 开始行
 * @param endRow 结束行
 * @param firstCol 开始列
 * @param endCol 结束列
 */
public static void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
                                 int firstCol, int endCol)
{
    // 构造constraint对象
    DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
    // 四个参数分别是:起始行、终止行、起始列、终止列
    CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
    // 数据有效性对象
    HSSFDataValidation dataValidationView = new HSSFDataValidation(regions, constraint);
    dataValidationView.createPromptBox(promptTitle, promptContent);
    sheet.addValidationData(dataValidationView);
}