002-poi-excel-导出设置单元格数据校验规则、筛选功能
一、数据验证概述
推荐以下操作在2007之后操作
1.1、查看excel的数据验证
1、进入

2、设置规则

通过验证条件允许,可以看到是每个单元格默认只成立一种条件
1.2、POI代码开发-数据验证
1.2.1、两个数之间
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);
}
1.2.2、选择【序列】
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);
}
1.2.3、列唯一
使用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);
002-poi-excel-导出设置单元格数据校验规则、筛选功能的更多相关文章
- [转载]Java读取Excel中的单元格数据
目前网上能找到的读取Excel表格中数据的两种比较好的方案:PageOffice好用开发效率高:POI免费.供大家参考,针对具体情况选择具体方案. 1. PageOffice读取excel impor ...
- jqgrid设置单元格数据
$("#gridid").jqGrid('setCell',rowid,icol,data); rowid为行ID,jqgrid内置的那个,从1开始 icol为列索引,从0开始, ...
- .Net 导出Excel时设置单元格的格式为文本类型
<td style= 'vnd.ms-excel.numberformat:@ ' align='right'>" & Format(Val(rowTitle.Item( ...
- 【手记】解决excel无法设置单元格颜色且界面怪异+桌面图标文字老有色块等问题
注:问题是在XP上遇到的,不知道是否适用其它系统 问题现象 excel 2010成这样了: 关键是设置不了单元格颜色,无论是文字颜色还是背景色都设置不了,设了没变化.同时会发现桌面图标的文字总有底色: ...
- Excel公式设置单元格颜色
Excel2010 “条件格式"-"新建规则"-"使用公式确定要设置格式的单元格" 公式如下: =OR(H2<=-20%,H2>=20%, ...
- java 使用poi导出Excel,设置单元格保护不可编辑
//sheet表加密:等效excel的审阅菜单下的保护工作表 sheet.protectSheet(new String("333"));//333是密码 更多设置请参考:http ...
- thinkphp3.2.3集成phpexcel1.8导出设置单元格合并
1 到这里下载classes里面的文件 https://github.com/PHPOffice/PHPExcel 2 然后放到 thinkphp的vendor 新建一个文件夹 Phpexcel 然 ...
- asp.net+nopi生成Excel遇到设置单元格值null问题
Npoi 生成excel报表功能很不错,功能也不用给大家介绍了.首先看遇到的问题吧! FileStream file = new FileStream(Server.MapPath("Tem ...
- C#导出Excel按照指定格式设置单元格属性值
最近项目中一直在写XML.Table.Excel之间的转化.之前一直都是不考虑格式的导出,今天给出一个格式,让按照格式导出,还真把我这新手为难了一翻,网上给出的资料基本一样.为了一个单元格文字变色纠结 ...
随机推荐
- Luogu P1114 “非常男女”计划/Luogu P2697 宝石串
Luogu P1114 "非常男女"计划/Luogu P2697 宝石串 (感觉我最近很爱做双倍经验的题啊) 使$d$等于第$i$个位置男生数(绿宝石数)减女生数(红宝石数)的差值 ...
- 我花了2个月时间,整理了100篇Linux技术精华,技术人必看
一个以技术为立身根基的教育机构做出来的微信号,干货程度会有多高? 马哥Linux运维公众号运营五年,从一开始的定位就是给技术人分享加薪干货的地方.这五年里,公众号运营最重的任务就是做内容.内容并不好做 ...
- [bzoj 3701] Olympic Games (莫比乌斯反演)
题目描述 给出n,m,l,r,modn,m,l,r,modn,m,l,r,mod 表示一个(n+1)∗(m+1)(n+1)*(m+1)(n+1)∗(m+1)的格点图,求能够互相看见的点对个数对modm ...
- Second Max of Array
Find the second max number in a given array. Example Given [1, 3, 2, 4], return 3. Given [1, 2], ret ...
- 45、[源码]-Spring容器创建-执行BeanFactoryPostProcessor
45.[源码]-Spring容器创建-执行BeanFactoryPostProcessor 5.invokeBeanFactoryPostProcessors(beanFactory);执行BeanF ...
- [Dart] final vs const
void main() { ; print(a); ; print(b); final c = 'Hello'; // c = 'Hello again'; // Uncomment to throw ...
- Flume实时监控目录sink到hdfs,再用sparkStreaming监控hdfs的这个目录,对数据进行计算
目标:Flume实时监控目录sink到hdfs,再用sparkStreaming监控hdfs的这个目录,对数据进行计算 1.flume的配置,配置spoolDirSource_hdfsSink.pro ...
- sql server newid() 的用法
sql newid()随机函数 从A表随机取2条记录,用SELECT TOP 10 * FROM ywle order by newid()order by 一般是根据某一字段排序,newid() ...
- SQL SERVER PIVOT使用
参照这个网址介绍 http://www.cnblogs.com/lwhkdash/archive/2012/06/26/2562979.html 一般SQL Server的函数都会识别为紫色,可是PI ...
- WINDOWS 10下64位本地 ORACLE 11 G安装完整教程
URL:https://www.cnblogs.com/count-mjb/p/7655592.html wssbht = (DESCRIPTION = (ADDRESS_LIST = (ADDRES ...