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);
}
}