hutool 工具 ExcelWriter 导出下拉数据使用

具体代码如下
//获取下拉数据
String[] splitV0164 = DictUtils.getStrArr(v0164);
//获取编码值
String[] strArrKeyV0164 = DictUtils.getStrArrKey(v0164);
//设置导航栏下拉提示
ExcelUtils.setDownBox(sheet, splitV0164, 0, 0,2,2);
//设置选择数据
ExcelUtils.setDownBox(sheet, strArrKeyV0164, 1, 1000,2,2);
具体代码:
复制代码
 //导出数据
        List<StorageStorehouseDto> routineList = null;

        // 写出到流
        ExcelWriter excelWriter = ExcelUtil.getWriter(true);
        // 设置别名
        excelWriter.addHeaderAlias("storeNum", "编号");
        
        try {
            if(null!=ids&&ids.size()==1&&ids.get(0)==0){
                routineList=new ArrayList<>();
                StorageStorehouseDto storageStorehouseDto=new StorageStorehouseDto();
                storageStorehouseDto.setId(0L);
                routineList.add(storageStorehouseDto);

                Sheet sheet = excelWriter.getSheet();
                Response<Object> v0164 = vcsParameterService.getDictinfo("V0164");
                String[] splitV0164 = DictUtils.getStrArr(v0164);
                String[] strArrKeyV0164 = DictUtils.getStrArrKey(v0164);
                //设置导航栏下拉提示
                ExcelUtils.setDownBox(sheet, splitV0164, 0, 0,2,2);
                //设置选择数据
                ExcelUtils.setDownBox(sheet, strArrKeyV0164, 1, 1000,2,2);

          

            }

            String fileName = "信息" + IdUtil.objectId() + ".xlsx";

            OutputStream outputStream = response.getOutputStream();
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            response.setHeader("Content-Disposition","attachment;filename=" + FileUtils.setFileDownloadHeader(request, fileName));

            // 只显示设置了别名的
            excelWriter.setOnlyAlias(true);
            // 写入excel
            excelWriter.write(routineList, true);
            // 写出
            excelWriter.flush(outputStream);

        } catch (Exception e) {
            log.error("业务导出EXCEL", e);
        } finally {
            // 释放内存
            excelWriter.close();
        }

    }
View Code
复制代码

 



posted @   星空物语之韵  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
历史上的今天:
2021-01-13 Postgresql常用函数整理
点击右上角即可分享
微信分享提示