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

哈尔滨网站建设多少钱我在百度下的订单如何查询

哈尔滨网站建设多少钱,我在百度下的订单如何查询,哪个网站做网站好,企业网站建设电话apache poi 提供了 DataValidation​ 接口 让我们可以轻松实现 Excel 下拉框数据局校验。但是下拉框联动校验是无法直接通过 DataValidation ​实现,所以我们可以通过其他方式间接实现。 ‍ 步骤如下: 创建一个隐藏 sheet private static void create…

apache poi 提供了 DataValidation​ 接口 让我们可以轻松实现 Excel 下拉框数据局校验。但是下拉框联动校验是无法直接通过 DataValidation ​实现,所以我们可以通过其他方式间接实现。

步骤如下:

  1. 创建一个隐藏 sheet
 private static void createHiddenSheet(List<String> provinceList, Map<String, String[]> regionMap, Workbook workbook) {String hiddenSheetName = "region";Sheet hiddenSheet = workbook.createSheet(hiddenSheetName);// 这里也可以设置 hidden 为 false 这样可以直接看到 sheet 内容workbook.setSheetHidden(workbook.getSheetIndex(hiddenSheet), true);}
  1. 将数据放入隐藏 sheet
        int rowNum = 0;// 第一行存放省数据Row row = hiddenSheet.createRow(rowNum);for (int i = 0; i < provinceList.size(); i++) {Cell cell = row.createCell(i);cell.setCellValue(provinceList.get(i));}rowNum++;for (String key : regionMap.keySet()) {String[] dataArray = regionMap.get(key);// 循环创建行,每行存放一个数组row = hiddenSheet.createRow(rowNum);// key 放在每行第一个,value 放在每行的后面Cell keyCell = row.createCell(0);keyCell.setCellValue(key);for (int i = 0, length = dataArray.length; i < length; i++) {Cell cell = row.createCell(i + 1);cell.setCellValue(dataArray[i]);}Name name = workbook.createName();// 将key 设置为下拉框的keyname.setNameName(key);String formula = hiddenSheetName + "!$B$" + (rowNum + 1) + ":$" + (convertNumberToLetter(dataArray.length + 1)) + "$" + (rowNum + 1);name.setRefersToFormula(formula);// 可以将formula 放在最后一列Cell formulaCell = row.createCell(dataArray.length + 1);formulaCell.setCellValue(formula);rowNum++;}
  1. 在主 sheet 中使用 formula 来使用隐藏 sheet 的数据
    DataValidationHelper helper = mainSheet.getDataValidationHelper();// 设置省份下拉框CellRangeAddressList provRangeAddressList = new CellRangeAddressList(1, 1000, 0, 0);// formula 为  region!$A$1:$E$1DataValidationConstraint dvConstraint = helper.createFormulaListConstraint("region!$A$1:$" + (convertNumberToLetter(provinceList.size())) + "$1");DataValidation provinceDataValidation = helper.createValidation(dvConstraint, provRangeAddressList);provinceDataValidation.setSuppressDropDownArrow(true);mainSheet.addValidationData(provinceDataValidation);
  1. 设置联动下拉框 DataValidation
 // 设置市下拉框  firstCol lastCol 根据实际情况设置CellRangeAddressList cityRange = new CellRangeAddressList(1, 1000, 1, 1);DataValidationConstraint cityConstraint = helper.createFormulaListConstraint("INDIRECT(A2)");DataValidation cityValidation = helper.createValidation(cityConstraint, cityRange);mainSheet.addValidationData(cityValidation);// 设置县下拉框 firstCol lastCol 根据实际情况设置CellRangeAddressList districtRange = new CellRangeAddressList(1, 1000, 2, 2);DataValidation districtValidation = helper.createValidation(helper.createFormulaListConstraint("INDIRECT(B2)"), districtRange);mainSheet.addValidationData(districtValidation);
  1. 完整代码如下:
package com.shang;import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/**
* @author: shangwei
* @date: 2024/11/3 13:01
*/
public class ExcelUtil {public static void createExcel(String path, List<String> provinceList, Map<String, String[]> regionMap) {try {Workbook workbook = new XSSFWorkbook();createHiddenSheet(provinceList, regionMap, workbook);Sheet mainSheet = workbook.createSheet("mainSheet");// 主sheet 第一行数据String[] titles = {"省", "市", "县"};int rowNum = 0;Row row = mainSheet.createRow(rowNum);for (int i = 0; i < titles.length; i++) {Cell cell = row.createCell(i);cell.setCellValue(titles[i]);}DataValidationHelper helper = mainSheet.getDataValidationHelper();// 设置省份下拉框CellRangeAddressList provRangeAddressList = new CellRangeAddressList(1, 1000, 0, 0);// formula 为  region!$A$1:$E$1DataValidationConstraint dvConstraint = helper.createFormulaListConstraint("region!$A$1:$" + (convertNumberToLetter(provinceList.size())) + "$1");DataValidation provinceDataValidation = helper.createValidation(dvConstraint, provRangeAddressList);provinceDataValidation.setSuppressDropDownArrow(true);mainSheet.addValidationData(provinceDataValidation);// 设置市下拉框  firstCol lastCol 根据实际情况设置CellRangeAddressList cityRange = new CellRangeAddressList(1, 1000, 1, 1);DataValidationConstraint cityConstraint = helper.createFormulaListConstraint("INDIRECT(A2)");DataValidation cityValidation = helper.createValidation(cityConstraint, cityRange);mainSheet.addValidationData(cityValidation);// 设置县下拉框 firstCol lastCol 根据实际情况设置CellRangeAddressList districtRange = new CellRangeAddressList(1, 1000, 2, 2);DataValidation districtValidation = helper.createValidation(helper.createFormulaListConstraint("INDIRECT(B2)"), districtRange);mainSheet.addValidationData(districtValidation);FileOutputStream fileOutputStream = new FileOutputStream(path);workbook.write(fileOutputStream);} catch (Exception e) {e.printStackTrace();}}private static void createHiddenSheet(List<String> provinceList, Map<String, String[]> regionMap, Workbook workbook) {String hiddenSheetName = "region";Sheet hiddenSheet = workbook.createSheet(hiddenSheetName);int rowNum = 0;// 第一行存放省数据Row row = hiddenSheet.createRow(rowNum);for (int i = 0; i < provinceList.size(); i++) {Cell cell = row.createCell(i);cell.setCellValue(provinceList.get(i));}rowNum++;for (String key : regionMap.keySet()) {String[] dataArray = regionMap.get(key);// 循环创建行,每行存放一个数组row = hiddenSheet.createRow(rowNum);// key 放在每行第一个,value 放在每行的后面Cell keyCell = row.createCell(0);keyCell.setCellValue(key);for (int i = 0, length = dataArray.length; i < length; i++) {Cell cell = row.createCell(i + 1);cell.setCellValue(dataArray[i]);}Name name = workbook.createName();// 将key 设置为下拉框的keyname.setNameName(key);String formula = hiddenSheetName + "!$B$" + (rowNum + 1) + ":$" + (convertNumberToLetter(dataArray.length + 1)) + "$" + (rowNum + 1);name.setRefersToFormula(formula);// 可以将formula 放在最后一列Cell formulaCell = row.createCell(dataArray.length + 1);formulaCell.setCellValue(formula);rowNum++;}// 这里也可以设置 hidden 为 false 这样可以直接看到 sheet 内容workbook.setSheetHidden(workbook.getSheetIndex(hiddenSheet), true);}/*** 将数字 1 到 26 转换为对应的字母 A 到 Z。** @param number 要转换的数字,范围是 1 到 26。* @return 对应的字母。*/public static String convertNumberToLetter(int number) {if (number < 1 || number > 26) {throw new IllegalArgumentException("Number must be between 1 and 26");}return String.valueOf((char) ('A' + number - 1));}public static void main(String[] args) {Map<String, String[]> regionMap = new HashMap<>();List<String> provinceList = Arrays.asList("湖北省", "湖南省", "广东省", "江苏省", "浙江省");regionMap.put("湖北省", new String[]{"武汉市", "黄石市", "十堰市", "宜昌市", "襄樊市", "鄂州市", "荆门市", "孝感市", "荆州市", "黄冈市", "咸宁市", "随州市"});regionMap.put("湖南省", new String[]{"长沙市", "株洲市", "湘潭市", "衡阳市", "邵阳市", "岳阳市", "常德市", "张家界市", "益阳市", "郴州市", "永州市", "怀化市"});regionMap.put("广东省", new String[]{"广州市", "韶关市", "深圳市", "珠海市", "汕头市", "佛山市", "江门市", "湛江市", "茂名市", "肇庆市", "惠州市", "梅州市", "汕尾市", "河源市", "阳江市", "清远市"});regionMap.put("江苏省", new String[]{"南京市", "无锡市", "徐州市", "常州市", "苏州市", "南通市", "连云港市", "淮安市", "盐城市", "扬州市", "镇江市", "泰州市", "宿迁市"});regionMap.put("浙江省", new String[]{"杭州市", "宁波市", "温州市", "嘉兴市", "湖州市", "绍兴市", "金华市", "衢州市", "舟山市", "台州市", "丽水市"});regionMap.put("武汉市", new String[]{"江岸镇", "江汉镇", "江夏镇", "硚口镇", "武昌镇", "江夏镇"});regionMap.put("黄石市", new String[]{"黄石港镇", "西塞山镇", "下陆镇", "大冶镇", "大冶镇"});String path = "/Users/shangwei/Desktop/example" + System.currentTimeMillis() + ".xlsx";createExcel(path, provinceList, regionMap);}}

相关 Maven 依赖

<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version></dependency>

运行截图:

​​运行截图


文章转载自:
http://titaness.c7625.cn
http://slashing.c7625.cn
http://walkover.c7625.cn
http://satrap.c7625.cn
http://heliotaxis.c7625.cn
http://t.c7625.cn
http://lammastide.c7625.cn
http://nonwhite.c7625.cn
http://baluster.c7625.cn
http://tiberium.c7625.cn
http://emersion.c7625.cn
http://hyp.c7625.cn
http://trijugous.c7625.cn
http://knob.c7625.cn
http://dewclaw.c7625.cn
http://straightjacket.c7625.cn
http://mariposa.c7625.cn
http://bungarotoxin.c7625.cn
http://colourful.c7625.cn
http://hornito.c7625.cn
http://hagiographer.c7625.cn
http://detection.c7625.cn
http://illusively.c7625.cn
http://chartaceous.c7625.cn
http://hop.c7625.cn
http://wardmote.c7625.cn
http://nucleolar.c7625.cn
http://somnambule.c7625.cn
http://submillimetre.c7625.cn
http://subinfeudatory.c7625.cn
http://rabia.c7625.cn
http://dirigibility.c7625.cn
http://rheumatiz.c7625.cn
http://gravicembalo.c7625.cn
http://daltonism.c7625.cn
http://rot.c7625.cn
http://prajna.c7625.cn
http://jasmine.c7625.cn
http://gleiwitz.c7625.cn
http://entourage.c7625.cn
http://unobvious.c7625.cn
http://shirk.c7625.cn
http://abb.c7625.cn
http://briery.c7625.cn
http://affiliate.c7625.cn
http://cornfield.c7625.cn
http://penny.c7625.cn
http://metachrome.c7625.cn
http://fuddled.c7625.cn
http://laniate.c7625.cn
http://diagnosis.c7625.cn
http://ligularia.c7625.cn
http://economical.c7625.cn
http://trisaccharide.c7625.cn
http://vinton.c7625.cn
http://tyrrhenian.c7625.cn
http://shapeliness.c7625.cn
http://unmodish.c7625.cn
http://rigescence.c7625.cn
http://hypersomnia.c7625.cn
http://anglicanism.c7625.cn
http://panegyrize.c7625.cn
http://germanise.c7625.cn
http://twopence.c7625.cn
http://azury.c7625.cn
http://fluoresce.c7625.cn
http://platynite.c7625.cn
http://armiger.c7625.cn
http://disaffinity.c7625.cn
http://undefendable.c7625.cn
http://fireclay.c7625.cn
http://catridges.c7625.cn
http://tractorcade.c7625.cn
http://enabled.c7625.cn
http://neurula.c7625.cn
http://backswept.c7625.cn
http://guttural.c7625.cn
http://diolefin.c7625.cn
http://suddenness.c7625.cn
http://labra.c7625.cn
http://jugendstil.c7625.cn
http://tripack.c7625.cn
http://shintoist.c7625.cn
http://acceptive.c7625.cn
http://lazar.c7625.cn
http://pyrenin.c7625.cn
http://brit.c7625.cn
http://conch.c7625.cn
http://carnage.c7625.cn
http://kiloton.c7625.cn
http://hashbury.c7625.cn
http://misarticulation.c7625.cn
http://monkish.c7625.cn
http://colon.c7625.cn
http://rotoscythe.c7625.cn
http://nephelite.c7625.cn
http://inorganic.c7625.cn
http://calculability.c7625.cn
http://cytotechnologist.c7625.cn
http://bailsman.c7625.cn
http://www.zhongyajixie.com/news/67181.html

相关文章:

  • 论坛网站 备案湖南做网站的公司
  • 成都航空公司官方网站正规营销培训
  • 网站建设公司找哪家重庆seo整站优化效果
  • 站酷网图片2345网址导航设置
  • 东莞技术支持网站建设专家网络运营课程培训班
  • 软件开发收费价目表江阴网站优化公司
  • 专业做排行的网站网站关键词排名优化
  • 网站制作 电子商城微信营销策略有哪些
  • 新网站如何做优化本地推荐本地推荐
  • 10.制作一个网站一般先要明确( )站内关键词排名软件
  • 礼服外贸网站长沙专业seo优化公司
  • 如何给网站添加统计代码百度下载安装
  • 狠狠做新网站网站制作免费
  • 美食网站设计的基本思路网络推广平台几大类
  • 查询网站whois品牌宣传策划方案
  • 俄罗斯网站建设公司汕头seo网站建设
  • 中地海外路桥建设有限公司网站百度代运营推广
  • 如何看网站做没做推广别人恶意点击我们竞价网站
  • 邯郸网站建设邯郸网站制作网站推广的平台
  • 网上接单网站公司网站制作需要多少钱
  • dreamweaver 网站模板竞价推广账户竞价托管费用
  • 网站建设需要的条件百度电脑版网页版
  • 代码做网站常用单词线上营销推广的公司
  • 网站建设的几点体会深圳将进一步优化防控措施
  • 网站建设公司 南京外贸平台推广
  • 厦门做网站培训百度注册
  • 威海建设委员会网站域名服务器ip地址查询
  • 做网站后台教程视频百度怎么优化排名
  • 网站栏目类别是什么意思广州外贸推广
  • 手机端网站建设广告词百度推广售后客服电话