0:原样式

未修改之前.png

冻结.png

1:前期数据准备(List<Bean> list);

2:导出代码(基于Ruoyi-vue SpringBoot后端版本);

  @GetMapping("/priceweek/importTemplate")
@Log(title = "导出周平均价格", businessType = BusinessType.EXPORT)
public AjaxResult importTemplate(DrWeekPrice drWeekPrice) throws IOException {
    SysDept sysDept=sysDeptService.selectDeptById(Long.parseLong(drWeekPrice.getMarketId()));
    List<DrWeekPrice> list = drWeekPriceService.selectDrWeekAvgPrice(drWeekPrice);
    //定义hutool格式
    ExcelWriter writer = ExcelUtil.getWriter();
    writer.autoSizeColumnAll(); //自动列宽 感觉不太好用
    writer.setColumnWidth(-1,20);
    writer.setRowHeight(-1,50);
    writer.setOnlyAlias(true); //将导出的excel表中的ID去掉。
    //冻结前两行
    writer.setFreezePane(2);
    OutputStream out =null;
    writer.addHeaderAlias("shopNumber","商户编号");
    writer.addHeaderAlias("shopName","商户名称");
    writer.addHeaderAlias("shopPeople","商户负责人");
    writer.addHeaderAlias("className","类别名称");
    writer.addHeaderAlias("product","规格型号");
    writer.addHeaderAlias("unit","单位");
    writer.addHeaderAlias("thisWeekPrice","本周总销售额");
    writer.addHeaderAlias("thisDayTrading","本周总销量");
    writer.addHeaderAlias("thisWeekAvgPrice","本周均价");
    writer.addHeaderAlias("lastWeekAvgPrice","上周均价");
    writer.addHeaderAlias("ringvalue","价格浮动");

    String fileweek= DateUtil.format(drWeekPrice.getSurveyDateWeek(), "yyyy-MM-dd");

    writer.merge(11, fileweek+"-"+sysDept.getDeptName()+"-"+"代表品周价格信息");

    writer.write(list,true);

    writer.renameSheet("all");
    String filename="代表品周价格.xls";
    out= new FileOutputStream(getAbsoluteFile(filename));
    writer.flush(out);

    return AjaxResult.success(filename);

}

3

多Sheet导出

标签: none

添加新评论