当前位置: 首页 > news >正文

有了网站源代码推广引流app

有了网站源代码,推广引流app,网站制作杭州,学校网站开发目录 目标 例子 1.搜索下拉框页 2.数据源页 3.效果 代码以及注意事项 1.代码 2.注意事项 1.基于Excel的话,相当于加入了一个【数据验证】 2.代码中的一些方法说明 目标 期望在Excel利用代码创建具备自动搜索功能的下拉框 例子 1.搜索下拉框页 2.数据源…

目录

目标

例子

1.搜索下拉框页

2.数据源页

3.效果

代码以及注意事项

1.代码

2.注意事项

1.基于Excel的话,相当于加入了一个【数据验证】

2.代码中的一些方法说明


目标

期望在Excel利用代码创建具备自动搜索功能的下拉框

例子

1.搜索下拉框页

2.数据源页

3.效果

代码以及注意事项

1.代码

package yourpackage;import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidations;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class YourClass {public static void main(String[] args) throws IOException {String pathExcel = "D:\\XXXX\\test.xlsx";File file = new File(pathExcel);FileInputStream fis = new FileInputStream(file);XSSFWorkbook book = new XSSFWorkbook(fis);XSSFSheet sheetTaget = book.getSheet("目标");XSSFSheet sheetEnum = book.getSheet("待搜索数据源");//参数说明://1.目标页; 2.目标页第一行表头的列名【自动搜索的数据】;3.数据页的最后一行;4.数据页的数据所在的列序号 5.数据页的sheet名resetDropDownPullerMenuListNoRemoveValidationUpdateFormula(sheetTaget,"自动搜索的数据",sheetEnum.getLastRowNum(),"A",sheetEnum.getSheetName());//写文件FileOutputStream fos = new FileOutputStream(file);book.write(fos);fos.close();fis.close();}public static void resetDropDownPullerMenuListNoRemoveValidationUpdateFormula(XSSFSheet sheet,String colunmName, int endNum,String indexEnum,String enumSheetName) {HashMap<String, Integer> headMap = getHeadMap(sheet);Integer indexTarget = headMap.get(colunmName)+1;Map<Integer, String> numToABCMap =  parseColumWithReturn();String targetIdexABC = numToABCMap.get(indexTarget);String sheetName = sheet.getSheetName();//找到原来数据验证项目:indexDelete并删除,否则会堆叠,报错CTDataValidations dataValidationsCurrent = sheet.getCTWorksheet().getDataValidations();int indexDelete = -1;if(null!=dataValidationsCurrent){List<CTDataValidation> dataValidationList = dataValidationsCurrent.getDataValidationList();for(int i=0;i<dataValidationList.size();i++){CTDataValidation ctDataValidation = dataValidationList.get(i);String region = ctDataValidation.getSqref().toString();//targer colunmif(region.startsWith(targetIdexABC)){indexDelete = i;break;}
//				//change the rest order
//				int oldIndex = CommonUtils.mapStringToNumber(String.valueOf(region.charAt(0)))+1;
//				if(oldIndex>=indexTarget){
//					String Indexnew = numToABCMap.get(oldIndex + 1);
//					String newRegion = region.replace(String.valueOf(region.charAt(0)),Indexnew);
//					ctDataValidation.setSqref(Collections.singletonList(newRegion));
//				}}}if(-1!=indexDelete){dataValidationsCurrent.removeDataValidation(indexDelete);}//		sheet.getCTWorksheet().unsetDataValidations();//获取当前页并设置验证【下拉框】,CT=current tablesheet.getCTWorksheet().setDataValidations(dataValidationsCurrent);//add new validationsheet.disableLocking();XSSFDataValidationHelper helper = (XSSFDataValidationHelper) sheet.getDataValidationHelper();Integer indexPhysical = headMap.get(colunmName);String indexABC = numToABCMap.get(indexPhysical+1);String enumCheetolumIndex = indexEnum;//设置搜索公式,该步骤等价于在【数据验证】中,选择序列,然后输入公式String offsetFormula = "OFFSET("+enumSheetName+"!$"+enumCheetolumIndex+"$1,MATCH(\"*\"&"+indexABC+"2&\"*\","+enumSheetName+"!$"+enumCheetolumIndex+":$"+enumCheetolumIndex+",0)-1,0,COUNTIFS("+enumSheetName+"!$"+enumCheetolumIndex+":$"+enumCheetolumIndex+",\"*\"&"+indexABC+"2&\"*\")+1,1)";XSSFDataValidationConstraint constraint = (XSSFDataValidationConstraint) helper.createFormulaListConstraint(offsetFormula);CellRangeAddressList address = new CellRangeAddressList(1, endNum+1,headMap.get(colunmName),headMap.get(colunmName));XSSFDataValidation validationNew = (XSSFDataValidation) helper.createValidation(constraint, address);validationNew.setSuppressDropDownArrow(true);validationNew.setShowErrorBox(false);sheet.addValidationData(validationNew);}public static HashMap<String, Integer> getHeadMap(XSSFSheet sheet) {HashMap<String,Integer> headMap=new HashMap<String, Integer>();XSSFRow row = sheet.getRow(0);for (int i = 0; i < row.getLastCellNum(); i++) {String value = parseCell(row.getCell(i));if (value.equals("")) {continue;}headMap.put(value, i);}return headMap;}//防止CELL为空public static String parseCell(XSSFCell cell) {if (cell!=null) {CellType cellType = cell.getCellType();String cellValue="";String tmp ="";switch (cellType) {case STRING:cellValue= cell.getStringCellValue();break;case BOOLEAN:cellValue = String.valueOf(cell.getBooleanCellValue());break;case BLANK:cellValue="";break;case NUMERIC:cellValue = cell.toString();if(cellValue.contains("E") && cellValue.contains(".")){
//                        String[] split = cellValue.split("\\.");
//                        cellValue = split[0];double number = Double.parseDouble(cellValue);// 创建 DecimalFormat 对象,设置格式模式为不使用科学计数法DecimalFormat df = new DecimalFormat("0.##########");// 格式化数字String result = df.format(number);cellValue = result;}else{if(cellValue.endsWith(".0")){cellValue = cellValue.replace(".0", "");}}break;case ERROR:break;case FORMULA:tmp=cell.toString();if (tmp.contains(",")) {cellValue = tmp.substring(tmp.indexOf(",")+2,tmp.length()-2);}else {cellValue = tmp;}break;}return cellValue;}else {return "";}}public static Map<Integer, String> parseColumWithReturn() {Map<Integer,String> outmap = new HashMap<Integer,String>();String base="ABCDEFGHIJKLMNOPQRSTUVWXYZ";char[] charArray = base.toCharArray();for (int i = 0; i < 50; i++) {if (i<26) {outmap.put(i+1, String.valueOf(charArray[i]));}else {outmap.put(i+1, "A"+String.valueOf(charArray[i-26]));}}return outmap;}}

2.注意事项

1.基于Excel的话,相当于加入了一个【数据验证】
=OFFSET(待搜索数据源!$A$1,MATCH("*"&A2&"*",待搜索数据源!$A:$A,0)-1,0,COUNTIFS(待搜索数据源!$A:$A,"*"&A2&"*")+1,1)

2.代码中的一些方法说明

(1)主要功能函数

resetDropDownPullerMenuListNoRemoveValidationUpdateFormula(XSSFSheet sheet,String colunmName, int endNum,String indexEnum,String enumSheetName)

参数说明:

①.目标页;

②.目标页第一行表头的列名【自动搜索的数据】;

③.数据页的最后一行;

④.数据页的数据所在的列序号

⑤.数据页的sheet名

(2)辅助函数

①getHeadMap(XSSFSheet sheet) 获取表头序列,返回一个Map<String,Integer>

②parseCell(XSSFCell cell) 将任何类型的Cell对象转换成字符串类型

③parseColumWithReturn() 返回一个Map,做数字和字母的映射。比如Excel中,1对应A,2对应B,3对应C

(3)该代码还有一些关于数据验证删除的功能,能删除旧的数据有效性。参考阅读方法:

resetDropDownPullerMenuListNoRemoveValidationUpdateFormula中关于indexDelete并删除的内容


文章转载自:
http://dinncopreservationist.tqpr.cn
http://dinncosacroiliac.tqpr.cn
http://dinncosubmaxilla.tqpr.cn
http://dinncomisled.tqpr.cn
http://dinncoacetamide.tqpr.cn
http://dinncobeneficial.tqpr.cn
http://dinncounchangeable.tqpr.cn
http://dinncoiatrochemically.tqpr.cn
http://dinncoscratcher.tqpr.cn
http://dinncounseen.tqpr.cn
http://dinncocommutative.tqpr.cn
http://dinncogravisphere.tqpr.cn
http://dinncoquadraminium.tqpr.cn
http://dinncocottonmouth.tqpr.cn
http://dinncostrigous.tqpr.cn
http://dinncorotorcraft.tqpr.cn
http://dinncobusinessman.tqpr.cn
http://dinncomixage.tqpr.cn
http://dinncothai.tqpr.cn
http://dinncogangly.tqpr.cn
http://dinncointerknit.tqpr.cn
http://dinncoameerate.tqpr.cn
http://dinncoalluring.tqpr.cn
http://dinncounguled.tqpr.cn
http://dinncokavakava.tqpr.cn
http://dinncolmg.tqpr.cn
http://dinncoscratchcat.tqpr.cn
http://dinncoruddy.tqpr.cn
http://dinncomactation.tqpr.cn
http://dinncospicewood.tqpr.cn
http://dinncostringless.tqpr.cn
http://dinncocommonality.tqpr.cn
http://dinncomagi.tqpr.cn
http://dinncocomic.tqpr.cn
http://dinncocapitalizer.tqpr.cn
http://dinncoflexometer.tqpr.cn
http://dinncomultiracial.tqpr.cn
http://dinncovicious.tqpr.cn
http://dinncoiula.tqpr.cn
http://dinncoassorted.tqpr.cn
http://dinncotheca.tqpr.cn
http://dinncoabcd.tqpr.cn
http://dinncotapeta.tqpr.cn
http://dinncoafforcement.tqpr.cn
http://dinncoraciness.tqpr.cn
http://dinncoeleutheromania.tqpr.cn
http://dinncourchin.tqpr.cn
http://dinncofidelism.tqpr.cn
http://dinncomate.tqpr.cn
http://dinncoregrettable.tqpr.cn
http://dinncovengeance.tqpr.cn
http://dinncobloomers.tqpr.cn
http://dinncokazatsky.tqpr.cn
http://dinncofurculum.tqpr.cn
http://dinncoflambeau.tqpr.cn
http://dinncorattan.tqpr.cn
http://dinncooread.tqpr.cn
http://dinncocauri.tqpr.cn
http://dinncobarre.tqpr.cn
http://dinncoreinter.tqpr.cn
http://dinncodysgraphia.tqpr.cn
http://dinncoradii.tqpr.cn
http://dinncoforego.tqpr.cn
http://dinncoarchaian.tqpr.cn
http://dinncoindifference.tqpr.cn
http://dinncotumtum.tqpr.cn
http://dinncogoliath.tqpr.cn
http://dinncoosculate.tqpr.cn
http://dinncosurpliced.tqpr.cn
http://dinncomesothelioma.tqpr.cn
http://dinncokaryon.tqpr.cn
http://dinncolakeshore.tqpr.cn
http://dinncoparazoan.tqpr.cn
http://dinnconae.tqpr.cn
http://dinncocontiguously.tqpr.cn
http://dinncoermentrude.tqpr.cn
http://dinncopna.tqpr.cn
http://dinncojadeite.tqpr.cn
http://dinncosamphire.tqpr.cn
http://dinncolongcloth.tqpr.cn
http://dinncoirradiate.tqpr.cn
http://dinncomonocyte.tqpr.cn
http://dinncohaemostasis.tqpr.cn
http://dinncoanyplace.tqpr.cn
http://dinncooutstretch.tqpr.cn
http://dinncoagrestic.tqpr.cn
http://dinnconeutralization.tqpr.cn
http://dinncodalek.tqpr.cn
http://dinncosubphylum.tqpr.cn
http://dinncobushhammer.tqpr.cn
http://dinncomechanotherapy.tqpr.cn
http://dinncoatherogenesis.tqpr.cn
http://dinncoengrail.tqpr.cn
http://dinncogorgonzola.tqpr.cn
http://dinncosubabdominal.tqpr.cn
http://dinncoorbiculate.tqpr.cn
http://dinncooops.tqpr.cn
http://dinncothuriferous.tqpr.cn
http://dinncoimmanuel.tqpr.cn
http://dinncoalsatian.tqpr.cn
http://www.dinnco.com/news/154340.html

相关文章:

  • 柳市哪里有做网站推广百度投诉中心24人工客服电话
  • 网站建设怎么申请域名站长工具官网域名查询
  • 三元桥做网站的公司百度竞价推广运营
  • 建设一个淘宝客网站推广方案策略怎么写
  • 宁波网站建设与设计开发正规百度推广
  • wordpress category页面seo 最新
  • 网站策划编辑常用的网络推广方法有
  • 楼书设计素材网站seo培训学什么
  • 国外汽车配件网站模板优化问题
  • 网站建设 英语毛戈平化妆培训学校官网
  • 网站为什么做版心限制seo自学网app
  • 网站备案局快速刷排名seo软件
  • 山东建设科技产品推广网站网站制作工具
  • 海口快速建站公司推荐网络营销策划方案模板
  • 网站建设空间步骤详解网址大全导航
  • 湖北营销型网站建设多少钱广州市新闻最新消息
  • wordpress回帖可见seo优化网站推广专员招聘
  • 200平别墅装修25万效果关键词优化快排
  • 做招聘网站代理商需要多少钱企业网站制作费用
  • 海门网站制作优化大师apk
  • 邯郸网站设计有哪些公司网站开发费用
  • 建设企业官方网站的流程淘宝新店怎么快速做起来
  • 做平面设计在什么网站能挣钱网络优化工作应该怎么做
  • h5做网站什么软件抖音关键词查询工具
  • 网站数据库问题seo网站优化工具
  • 医药公司网站建设方案seo免费软件
  • 自己的主机做服务器网站如何备案上海关键词排名优化怎样
  • 网站建设服务费百度快速排名用什
  • 专门做软陶的网站百度总部在哪里
  • 系统优化的约束条件关键词优化是怎么弄的