标签:ast ddr http div erb unique sele 概述 min
推荐以下操作在2007之后操作
1、进入
2、设置规则
通过验证条件允许,可以看到是每个单元格默认只成立一种条件
public void excelRuleNumberBetween(Sheet sheet, int min, int max, int firstRow, int lastRow, int firstCol, int lastCol){ DataValidationHelper helper = sheet.getDataValidationHelper(); CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);//设置行列范围 //设置数据 DataValidationConstraint constraint = helper.createIntegerConstraint(DataValidationConstraint.OperatorType.BETWEEN, String.valueOf(min),String.valueOf(max)); DataValidation dataValidation = helper.createValidation(constraint, addressList); dataValidation.createErrorBox("输入值类型或大小有误", String.format("请输入%s~%s之间的数值",min,max)); //处理Excel兼容性问题 if(dataValidation instanceof XSSFDataValidation) { dataValidation.setSuppressDropDownArrow(true); dataValidation.setShowErrorBox(true); }else { dataValidation.setSuppressDropDownArrow(false); } sheet.addValidationData(dataValidation); }
public void excelRuleSelect(Sheet sheet, String[] rule, int firstRow, int lastRow, int firstCol, int lastCol) { DataValidationHelper helper = sheet.getDataValidationHelper(); CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); DataValidationConstraint constraint = helper.createExplicitListConstraint(rule); DataValidation dataValidation = helper.createValidation(constraint, addressList); dataValidation.createErrorBox("输入有误", "请选择下拉参数"); if (dataValidation instanceof XSSFDataValidation) { dataValidation.setSuppressDropDownArrow(true); dataValidation.setShowErrorBox(true); } else { dataValidation.setSuppressDropDownArrow(false); } sheet.addValidationData(dataValidation); }
使用excel设置
POI设置
public void excelRuleUniqueue(Sheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) { Row row = sheet.getRow(0); Cell cell = row.getCell(firstCol); String r = ((XSSFCell) cell).getCTCell().getR(); r = r.substring(0, 1); DataValidationHelper helper = sheet.getDataValidationHelper(); CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol); //唯一 DataValidationConstraint constraint = helper.createCustomConstraint(MessageFormat.format("COUNTIF({0}:{0},{0}2)=1",r)); DataValidation dataValidation = helper.createValidation(constraint, addressList); dataValidation.createErrorBox("错误:", "赋值属性列不允许重复"); dataValidation.setShowErrorBox(true); dataValidation.setEmptyCellAllowed(true); dataValidation.setSuppressDropDownArrow(true); dataValidation.setShowPromptBox(true); dataValidation.setErrorStyle(DataValidation.ErrorStyle.STOP); sheet.addValidationData(dataValidation); }
二、其他
2.1、列筛选
查看excel实现
POI代码
Sheet sheetCreat = wbCreat.createSheet(sheet.getSheetName()); CellRangeAddress c = CellRangeAddress.valueOf(CELL_RANGE_ADDRESS); sheetCreat.setAutoFilter(c);
标签:ast ddr http div erb unique sele 概述 min
原文地址:https://www.cnblogs.com/bjlhx/p/11240696.html