java下载xls填充下拉选动态数据

1下载模版时,平台类目需要填充动态数据也就是平台维护的类目

2创建一个sheet,命名数据A,之后将数据A隐藏

3设置数据有效性,下拉选和数据A(sheet)关联

备注:如果不是动态数据,可以直接设置数据有效性,忽略第4步

4部分实现代码如下:

public String exportTemplate() {
    
    //根据店获取平台类目
    ContractCateQueryRequest cateQueryRequest = new ContractCateQueryRequest();
    cateQueryRequest.setStoreId(storeId);
    List<Long> cateIds = contractCateRepository.findAll(cateQueryRequest.getWhereCriteria()).stream().map(ContractCate::getGoodsCate).map(GoodsCate::getCateId).collect(Collectors.toList());
    List<GoodsCate> cates = goodsCateRepository.queryLeaf(cateIds);

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         InputStream is = file.getInputStream();
         Workbook wk = WorkbookFactory.create(is)) {
        Sheet cateSheet = wk.getSheetAt(1);
        //填放分类数据
        int cateSize = cates.size();
        for (int i = 0; i < cateSize; i++) {
            GoodsCate cate = cates.get(i);
            // 查询商品分类所有父分类名称
            String allCateName = queryParentCate(cate.getCateId());
            cateSheet.createRow(i).createCell(0).setCellValue(String.valueOf(cate.getCateId()).concat("_").concat(allCateName));
        }

        Sheet brandSheet = wk.getSheetAt(2);
        int brandSize = brands.size();
        for (int i = 0; i < brandSize; i++) {
            GoodsBrandVO brand = brands.get(i);
            brandSheet.createRow(i).createCell(0).setCellValue(String.valueOf(brand.getBrandId()).concat("_").concat(brand.getBrandName()));
        }

        wk.write(baos);
        return new BASE64Encoder().encode(baos.toByteArray());
    } catch (Exception e) {
        throw new SbcRuntimeException(CommonErrorCode.FAILED, e);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值