导入--动态下拉框_easypoi addresslist-程序员宅基地

技术标签: hive  java  oracle  杂七杂八  hadoop  poi  

导入的时候,一般会有模版下载,那么会涉及到下拉框的情况,此下拉框为动态生成,今天我们来看下
所用工具easypoi

@Override
public void downLoadTemplete(HttpServletResponse response) throws Exception {
        //  模版下载,空数据,列对就可以了
        List<ImportBasicPersonVo> importBasicPersonVos = new ArrayList<>();

        // 文件保存路径
        String tempZipFilePath = "zipTempPath";

        // 创建xls文件
        File tempXlsxFile = new File(tempZipFilePath + File.separator + "import_person.xls");
        OutputStream xlsxOut = new FileOutputStream(tempXlsxFile);

        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ImportBasicPersonVo.class,
                importBasicPersonVos);

        // 设置下拉
        setSheetDropDown(workbook);
        workbook.write(xlsxOut);
}

设置下拉,即从数据库中查询要下拉的数据,然后设置,经过实践,当下拉中显示的字符总数超过255字节的时候,会报错,这里两种情况分别展示

// 显示的示例表格
        Sheet sheetAt = workbook.getSheetAt(0);
        // 下拉数据,绑定后就隐藏的表格
        Sheet hidden = workbook.createSheet("hidden");
        Cell cell = null;
        //下拉数据
        List<String> orgList = orgService.list().stream().map(org -> org.getName()).collect(Collectors.toList());
        // 将数据都放入hidden中 
       for (int i = 0, length = orgList.size(); i < length; i++)
        {
            String name = orgList.get(i);
            Row row = hidden.createRow(i);
            cell = row.createCell(0);
            cell.setCellValue(name);
        }

        Name namedCell = workbook.createName();
        // 绑定name
        namedCell.setNameName("hidden");
        // 在hidden中数据要存放的位置
        namedCell.setRefersToFormula("hidden!$A$1:$A$" + orgList.size());
        DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");

        // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
        CellRangeAddressList addressList = new CellRangeAddressList(1, 100, 8, 8);
        HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
        //将第二个sheet设置为隐藏
        workbook.setSheetHidden(1, false);
        if (null != validation)
        {
            sheetAt.addValidationData(validation);// 将数据加入到示例导出表格中 位置为1, 100, 8, 8
        }
//=====================这是大数据量的下拉,下面是普通下拉===============================
 // 准备下拉列表数据
        List<DictGroupItemVo> dictGroupAndItemList = basicDictGroupMapper.getDictGroupAndItemList(Arrays.asList("person_type", "id_type", "degree", "nation"));
        List<String> personTypeList = dictGroupAndItemList.stream().filter(dictGroupItemVo -> dictGroupItemVo.getGroupCode().equals("person_type")).map(dictGroupItemVo -> dictGroupItemVo.getName()).collect(Collectors.toList());
        List<String> idTypeList = dictGroupAndItemList.stream().filter(dictGroupItemVo -> dictGroupItemVo.getGroupCode().equals("id_type")).map(dictGroupItemVo -> dictGroupItemVo.getName()).collect(Collectors.toList());
        List<String> degreeList = dictGroupAndItemList.stream().filter(dictGroupItemVo -> dictGroupItemVo.getGroupCode().equals("degree")).map(dictGroupItemVo -> dictGroupItemVo.getName()).collect(Collectors.toList());
        List<String> nationList = dictGroupAndItemList.stream().filter(dictGroupItemVo -> dictGroupItemVo.getGroupCode().equals("nation")).map(dictGroupItemVo -> dictGroupItemVo.getName()).collect(Collectors.toList());
//        List<String> orgList = orgService.list(new QueryWrapper<Org>().select().eq(ColumnNameConstants.DELETE_STATUS, 0)).stream().map(org -> org.getName()).collect(Collectors.toList());
        // 获取当前用户有权限的组织集合
//        List<String> orgList = orgService.queryOrgListByUserId().stream().map(org -> org.getName()).collect(Collectors.toList());

        //  类别 证件类型  组织 学历 民族  性别

        // 设置第一列的1-100行为下拉列表
        CellRangeAddressList personRegions = new CellRangeAddressList(1, 100, 5, 5);
        CellRangeAddressList idTypeRegions = new CellRangeAddressList(1, 100, 6, 6);
        CellRangeAddressList degreeRegions = new CellRangeAddressList(1, 100, 11, 11);
        CellRangeAddressList nationRegions = new CellRangeAddressList(1, 100, 12, 12);
        CellRangeAddressList sexRegions = new CellRangeAddressList(1, 100, 4, 4);
//        CellRangeAddressList orgRegions = new CellRangeAddressList(1, 100, 8, 8);
        // 创建下拉列表数据
        DVConstraint personConstraint = null;
        DVConstraint idTypeConstraint = null;
        DVConstraint degreeConstraint = null;
        DVConstraint nationConstraint = null;
        DVConstraint sexConstraint = null;
        DVConstraint orgConstraint = null;
        if (CollectionUtil.isNotEmpty(personTypeList)) {
            personConstraint = DVConstraint.createExplicitListConstraint(personTypeList.toArray(new String[personTypeList.size()]));
            idTypeConstraint = DVConstraint.createExplicitListConstraint(idTypeList.toArray(new String[idTypeList.size()]));
            degreeConstraint = DVConstraint.createExplicitListConstraint(degreeList.toArray(new String[degreeList.size()]));
            nationConstraint = DVConstraint.createExplicitListConstraint(nationList.toArray(new String[nationList.size()]));
            sexConstraint = DVConstraint.createExplicitListConstraint(new String[]{"男", "女"});
//            orgConstraint = DVConstraint.createExplicitListConstraint(orgList.toArray(new String[orgList.size()]));
        }

        // 绑定
        HSSFDataValidation personValidation = new HSSFDataValidation(personRegions, personConstraint);
        HSSFDataValidation idTypeValidation = new HSSFDataValidation(idTypeRegions, idTypeConstraint);
        HSSFDataValidation degreeValidation = new HSSFDataValidation(degreeRegions, degreeConstraint);
        HSSFDataValidation nationValidation = new HSSFDataValidation(nationRegions, nationConstraint);
        HSSFDataValidation sexValidation = new HSSFDataValidation(sexRegions, sexConstraint);
//        HSSFDataValidation orgValidation = new HSSFDataValidation(orgRegions, orgConstraint);

        sheetAt.addValidationData(personValidation);
        sheetAt.addValidationData(idTypeValidation);
        sheetAt.addValidationData(degreeValidation);
        sheetAt.addValidationData(nationValidation);
        sheetAt.addValidationData(sexValidation);
//        sheetAt.addValidationData(orgValidation);

可以看到 其中orgValidation 开始也是用大多数普通下拉的,但是由于数据了较大,报错255,百度后,单独提出去了,位置都是(1,100,8,8)这样可以达到大数据下拉框的展示,并且不报错

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_32419139/article/details/120345295

智能推荐

树莓派4B新手配置(无显示屏、无网线、同一WiFi)_2020-08-20-raspios-buster-armhf-full-程序员宅基地

文章浏览阅读4.6k次,点赞10次,收藏37次。前期准备树莓派:4B#插入图片树莓派系统镜像:2020-08-20-raspios-buster-armhf-full.img#插入图片读卡器、SD卡(≥16G,Class 10及以上就行,我这里用32G)#插入图片烧录软件:SDFormatter、Win32DiskImager链接:https://pan.baidu.com/s/1AOdW3ANlwJtfyOg1TtOzLw 提取码:4zcn#插入图片ssh连接软件:这里我使用Xshell,其他ssh软件均可.._2020-08-20-raspios-buster-armhf-full

(转载)java synchronized详解-程序员宅基地

文章浏览阅读422次。java synchronized详解记下来,很重要。Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码。 一、当两个并发线程访问同一个对象object中的这个synchronized(this)同步代码块时,一个时间内只能有一个线程得到执行。另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块..._java make synchronized invalid

Android 多种投屏神器(Vysor,Total Control,scrcpy )-程序员宅基地

文章浏览阅读1.9w次,点赞6次,收藏32次。一,Vysor1,Vysor特点及优点特点或者说优点:极强的跨平台性能,Mac、Windows、Linux系统上都可以用;免费;无需Android系统Root 即可玩转电脑控制Android 设备;2,官网https://www.vysor.io/3,使用3.1,Win客户端(建议使用)直接下载windows客户端安装,运行就可以使用,使用也很简单,可以通过局域网和数据线连接Android设备,然后实现投屏;3.2,Chrome浏览器3.2.1,从官网Download进入_total control

Java反射机制_object o3 = m; object o4 = n; system.out.println(o-程序员宅基地

文章浏览阅读144次。概念:在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法和属性;这种动态获取信息以及动态调用对象方法的功能称为 Java 语言的反射机制。简单来说,反射机制指的是程序在运行时能够获取自身的信息。在 Java 中,只要给定类的名字,就可以通过反射机制来获得类的所有信息。类的加载机制:new 对象()1.JVM加载对象.class文件1.1JVM在硬盘找对象.class文件并读取到内存中1.2JVM自动创建..._object o3 = m; object o4 = n; system.out.println(o3 == o4)

NDK各个版本,待后续更新_android-ndk-r10e和ndk 29差别-程序员宅基地

文章浏览阅读414次。ndk_r15c (July 2017)Windows 32-bit :https://dl.google.com/android/repository/android-ndk-r15c-windows-x86.zipWindows 64-bit :https://dl.google.com/android/repository/android-ndk-r15c-windows-x86_64.zipMac OS X :https://dl.google.com/android/repositor_android-ndk-r10e和ndk 29差别

Linux常用命令—grep_linux命令+grep-程序员宅基地

文章浏览阅读4.1k次,点赞3次,收藏16次。简介grep命令(Global Regular Expression Print)是 Linux系统中一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来 。grep 是linux中最为常用的三大文本(awk,sed,grep)处理工具之一,所以有必要掌握其用法。grep家族总共有三个成员构成:grep、egrep、fgrep。使用格式grep [选项] ..._linux命令+grep

随便推点

easyui(控件权限树)_easyui实现权限勾选树-程序员宅基地

文章浏览阅读338次。easyui(控件权限树)二星权限设计思路:菜单不同的原因在于,利用不同menuid进行查询,原本默认查询的是所有菜单,是通过-1去查的;menuid由来:是登录用户id查询中间表数据所得来的今天类容是在 https://blog.csdn.net/wx1762813417/article/details/97619466 这篇博客上增加一些登入权限MenuDao与上..._easyui实现权限勾选树

Cookie,会话,令牌-程序员宅基地

文章浏览阅读804次。会话cookieAre you new to web-development, feeling confused with different Web Storage elements? 您是Web开发的新手,对不同的Web存储元素感到困惑吗? If yes, then you are at the right place This article will give you a brief e..._会话和令牌

Linux查找文本中指定字符的小技巧_linux查找指定字符后的数据-程序员宅基地

文章浏览阅读3.6k次。在Linux的vi编辑器中,如果要查看指定文件中的某项内容,由于内容过于庞大,可以打开vi编辑器后再打一个【/】,括号中间的字符,然后输入你要查找的字符这样就可以找到你需要的字符了,方便我们查看大容量的日志文件。_linux查找指定字符后的数据

编译chromium 总结_<includepath>$(includepath);$(dxsdk_dir)include</i-程序员宅基地

文章浏览阅读2.5k次。编译chromium 总结http://www.chromium.org/developers/how-tos/build-instructions-windows这是官网的详细地址,但我只用他的说明还不够 可以参考这篇文章http://blog.sina.com.cn/s/blog_41608ead0101578b.htmlwin7+vs2010+vs2010SP1+DIR_$(includepath);$(dxsdk_dir)include

Struts-笔记-2-程序员宅基地

文章浏览阅读61次。2 .搭建Struts开发环境 2.1 搭建环境l 导入jar 包。 Add Library 导入jar包 l 建立一个配置文件:struts-config.xml &lt...

【杭电oj】1872 - 稳定排序(结构体排序)_wygoj-程序员宅基地

文章浏览阅读695次。稳定排序Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4632 Accepted Submission(s): 1802Problem Description大家都知道,快速排序是不稳定的排序方法。_wygoj

推荐文章

热门文章

相关标签