easyExcel 写复杂表头

news2024/9/23 7:28:38

写模板

模板图片:
在这里插入图片描述
实体类(这里没有用@Data 是因为Lombok和easyExcal的版本冲突,在导入读取的时候获取不到值)

package cn.iocoder.yudao.module.project.controller.admin.goods.vo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/**
 * 商品下载模板
 * @author px
 */
public class GoodsTemplateExcelVO {
    @ExcelProperty(index = 0)
    private String bn;

    @ExcelProperty(index = 1)
    private String productName;

    @ExcelProperty(index = 2)
    private String brandNameCn;

    @ExcelProperty(index = 3)
    private String brandNameEn;

    @ExcelProperty(index = 4)
    private String brandLogo;

    @ExcelProperty(index = 5)
    private String url;

    @ExcelProperty(index = 6)
    private String jingle;

    @ExcelProperty(index = 7)
    private String categoryName1;

    @ExcelProperty(index = 8)
    private String categoryName2;

    @ExcelProperty(index = 9)
    private String categoryName3;

    @ExcelProperty(index = 10)
    private String unit;

    @ExcelProperty(index = 11)
    private String model;

    @ExcelProperty(index = 12)
    private String pakeageSpec;

    @ExcelProperty(index = 13)
    private String taxCode;

    @ExcelProperty(index = 14)
    private String outputTaxRate;

    @ExcelProperty(index = 15)
    private String codeBar;

    @ExcelProperty(index = 16)
    private BigDecimal price;

    @ExcelProperty(index = 17)
    private BigDecimal actualPrice;

    @ExcelProperty(index = 18)
    private String discountRate;

    @ExcelProperty(index = 19)
    private String isReturnStr;

    @ExcelProperty(index = 20)
    private String onlineStateStr;

    @ExcelProperty(index = 21)
    private Integer deliveryTime;

    @ExcelProperty(index = 22)
    private Integer arrivalTime;

    @ExcelProperty(index = 23)
    private Integer batchNum;

    @ExcelProperty(index = 24)
    private String firstAreaName;

    @ExcelProperty(index = 25)
    private String secondAreaName;

    @ExcelProperty(index = 26)
    private String thirdAreaName;

    @ExcelProperty(index = 27)
    private String storageArea;

    @ExcelProperty(index = 28)
    private Integer storage;

    @ExcelProperty(index = 29)
    private String attrJson;

    @ExcelProperty(index = 30)
    private String exceptionList;

    @ExcelIgnore
    private String projectName;

    @ExcelIgnore
    private Integer queueId;

    public String getBn() {
        return bn;
    }

    public void setBn(String bn) {
        this.bn = bn;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getBrandNameCn() {
        return brandNameCn;
    }

    public void setBrandNameCn(String brandNameCn) {
        this.brandNameCn = brandNameCn;
    }

    public String getBrandNameEn() {
        return brandNameEn;
    }

    public void setBrandNameEn(String brandNameEn) {
        this.brandNameEn = brandNameEn;
    }

    public String getBrandLogo() {
        return brandLogo;
    }

    public void setBrandLogo(String brandLogo) {
        this.brandLogo = brandLogo;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getJingle() {
        return jingle;
    }

    public void setJingle(String jingle) {
        this.jingle = jingle;
    }

    public String getCategoryName1() {
        return categoryName1;
    }

    public void setCategoryName1(String categoryName1) {
        this.categoryName1 = categoryName1;
    }

    public String getCategoryName2() {
        return categoryName2;
    }

    public void setCategoryName2(String categoryName2) {
        this.categoryName2 = categoryName2;
    }

    public String getCategoryName3() {
        return categoryName3;
    }

    public void setCategoryName3(String categoryName3) {
        this.categoryName3 = categoryName3;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getPakeageSpec() {
        return pakeageSpec;
    }

    public void setPakeageSpec(String pakeageSpec) {
        this.pakeageSpec = pakeageSpec;
    }

    public String getTaxCode() {
        return taxCode;
    }

    public void setTaxCode(String taxCode) {
        this.taxCode = taxCode;
    }

    public String getOutputTaxRate() {
        return outputTaxRate;
    }

    public void setOutputTaxRate(String outputTaxRate) {
        this.outputTaxRate = outputTaxRate;
    }

    public String getCodeBar() {
        return codeBar;
    }

    public void setCodeBar(String codeBar) {
        this.codeBar = codeBar;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getActualPrice() {
        return actualPrice;
    }

    public void setActualPrice(BigDecimal actualPrice) {
        this.actualPrice = actualPrice;
    }

    public String getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(String discountRate) {
        this.discountRate = discountRate;
    }

    public String getIsReturnStr() {
        return isReturnStr;
    }

    public void setIsReturnStr(String isReturnStr) {
        this.isReturnStr = isReturnStr;
    }

    public String getOnlineStateStr() {
        return onlineStateStr;
    }

    public void setOnlineStateStr(String onlineStateStr) {
        this.onlineStateStr = onlineStateStr;
    }

    public Integer getDeliveryTime() {
        return deliveryTime;
    }

    public void setDeliveryTime(Integer deliveryTime) {
        this.deliveryTime = deliveryTime;
    }

    public Integer getArrivalTime() {
        return arrivalTime;
    }

    public void setArrivalTime(Integer arrivalTime) {
        this.arrivalTime = arrivalTime;
    }

    public Integer getBatchNum() {
        return batchNum;
    }

    public void setBatchNum(Integer batchNum) {
        this.batchNum = batchNum;
    }

    public String getFirstAreaName() {
        return firstAreaName;
    }

    public void setFirstAreaName(String firstAreaName) {
        this.firstAreaName = firstAreaName;
    }

    public String getSecondAreaName() {
        return secondAreaName;
    }

    public void setSecondAreaName(String secondAreaName) {
        this.secondAreaName = secondAreaName;
    }

    public String getThirdAreaName() {
        return thirdAreaName;
    }

    public void setThirdAreaName(String thirdAreaName) {
        this.thirdAreaName = thirdAreaName;
    }

    public String getStorageArea() {
        return storageArea;
    }

    public void setStorageArea(String storageArea) {
        this.storageArea = storageArea;
    }

    public Integer getStorage() {
        return storage;
    }

    public void setStorage(Integer storage) {
        this.storage = storage;
    }

    public String getAttrJson() {
        return attrJson;
    }

    public void setAttrJson(String attrJson) {
        this.attrJson = attrJson;
    }

    public String getExceptionList() {
        return exceptionList;
    }

    public void setExceptionList(String exceptionList) {
        this.exceptionList = exceptionList;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public Integer getQueueId() {
        return queueId;
    }

    public void setQueueId(Integer queueId) {
        this.queueId = queueId;
    }

    public GoodsTemplateExcelVO(){

    }

    public GoodsTemplateExcelVO(String bn) {
        this.bn = bn;
        this.productName = "测试商品";
        this.brandNameCn = "品牌";
        this.brandNameEn = "pingpai";
        this.brandLogo = "https://img30.360buyimg.com/jgsq-productsoa/jfs/t1…5298/88691/63da0918Fb060cb06/6929f345feb64ed2.jpg";
        this.url = "https://www.ofs.cn/product-394804.html";
        this.jingle = "介绍";
        this.categoryName1 = "工具/工具耗材";
        this.categoryName2 = "手动工具";
        this.categoryName3 = "扳手";
        this.unit = "单位";
        this.model = "T88110-27";
        this.pakeageSpec = "1*1*1";
        this.taxCode = "";
        this.outputTaxRate = "13%";
        this.codeBar = "";
        this.discountRate = "20%";
        this.isReturnStr = "允许";
        this.onlineStateStr = "上架";
        this.deliveryTime = 1;
        this.arrivalTime = 1;
        this.batchNum = 2;
        this.firstAreaName = "全国";
        this.secondAreaName = "";
        this.thirdAreaName = "";
        this.storageArea = "重庆";
        this.storage = 999;
        this.attrJson = "保质期:12个月;" +
                "商品简介:徐福记 卷心酥 105g 香浓奶油味";
    }
}

public void downloadGoodsTemplateFile(HttpServletResponse response) {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=商品模板.xls");
      
        GoodsTemplateExcelVO goodsTemplateExcelVO = new GoodsTemplateExcelVO("123");
        List<GoodsTemplateExcelVO> goodsTemplateExcelVOList = new ArrayList<>();
        goodsTemplateExcelVOList.add(goodsTemplateExcelVO);
        try {
         // 这里需要设置不关闭流
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            //设置背景颜色
            headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
            //内容策略
            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            //设置 水平居中
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                    new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
            EasyExcel.write(response.getOutputStream()).autoCloseStream(Boolean.FALSE)
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .head(mergeGoodsDetailHead()).sheet("商品信息")
                    //获取数据填充
                    .doWrite(goodsTemplateExcelVOList);
        } catch (Exception e) {
        }
    }

自定义头部

private List<List<String>> mergeGoodsDetailHead() {
        String title = "XXX信息统计报表";
        List<List<String>> list = new ArrayList<>();
        String erTitle = "MRO标品SKU 商品名称 品牌中文名称 品牌英文名称 品牌图片链接 商品链接 商品介绍 一级分类名称 二级分类名称 " +
                "三级分类名称 商品单位 商品型号 包装规格 税收编码 销售税税率 条形码 官网价 协议价 折扣率 允许退换货(允许,不允许) 上下架状态(下架,上架) 预计发货时间(天) " +
                "预计补货时间(天) 最小起订量 一级供货地址 二级供货地址 三级供货地址 库存所在地 库存 类目属性";
        Arrays.stream(erTitle.split(" ")).forEach(name -> {
            List<String> head = new ArrayList<>();
            head.add(title);
            head.add(name);
            list.add(head);
        });
        return list;
    }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/357129.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

编译安装MySQL

MySQL 5.7主要特性 随机root 密码&#xff1a;MySQL 5.7 数据库初始化完成后&#xff0c;会自动生成一个 rootlocalhost 用户&#xff0c;root 用户的密码不为空&#xff0c;而是随机产生一个密码。原生支持&#xff1a;Systemd 更好的性能&#xff1a;对于多核CPU、固态硬盘、…

【蓝桥集训】第四天——双指针

作者&#xff1a;指针不指南吗 专栏&#xff1a;Acwing 蓝桥集训每日一题 &#x1f43e;或许会很慢&#xff0c;但是不可以停下&#x1f43e; 文章目录1.字符串删减2.最长连续不重复子序列3.数组元素的目标和1.字符串删减 给定一个由 n 个小写字母构成的字符串。 现在&#xff…

GCC 同名符号冲突解决办法

一、绪论 作为 C/C 的开发者&#xff0c;大多数都会清楚课本上动态库以及静态库的优缺点&#xff0c;在教科书上谈及到动态库的一个优点是可以节约磁盘和内存的空间&#xff0c;多个可执行程序通过动态库加载的方式共用一段代码段 &#xff1b;而时至今日&#xff0c;再看看上…

数据库浅谈之常见树结构

数据库浅谈之常见树结构 HELLO&#xff0c;各位博友好&#xff0c;我是阿呆 &#x1f648;&#x1f648;&#x1f648; 这里是数据库浅谈系列&#xff0c;收录在专栏 DATABASE 中 &#x1f61c;&#x1f61c;&#x1f61c; 本系列阿呆将记录一些数据库领域相关的知识 &#…

metasploit穷举模块

目录 工具介绍 常用模块 参数介绍 工具使用 工具介绍 Metasploit框架(Metasploit Framework, MSF)是一个开源工具&#xff0c; 旨在方便渗透测试&#xff0c;它是由Ruby程序语言编写的模板化框架&#xff0c;具有很好的扩展性&#xff0c;便于渗透测试人员开发、使用定制的…

浅析C++指针与引用,栈传递的关系

目录 前言 C 堆指针 栈指针 常量指针 指针常量 引用 常量引用 总结 前言 目前做了很多项目&#xff0c;接触到各种语言&#xff0c;基本上用什么学什么&#xff0c;语言的边际就会很模糊&#xff0c;实际上语言的设计大同小异&#xff0c;只是语言具备各自的特性区别。…

Python学习-----模块3.0(正则表达式-->re模块)

目录 前言&#xff1a; 导入模块 1.re.match() 函数 &#xff08;1&#xff09;匹配单个字符 &#xff08;2&#xff09;匹配多个字符 (3) 匹配开头和结尾 2.re.search() 函数 3.re.findall() 函数 4.re.finditer() 函数 5.re.split() 函数 6.re.sub() 函数 7.re.sub…

JAVA BIO,NIO,AIO区别(建议收藏)

Java中的IO原理 首先Java中的IO都是依赖操作系统内核进行的&#xff0c;我们程序中的IO读写其实调用的是操作系统内核中的read&write两大系统调用。 操作系统内核是如何进行IO交互的呢&#xff1f; 网卡中的收到经过网线传来的网络数据&#xff0c;并将网络数据写到内存…

Flink01: 基本介绍

一、什么是Flink 1. Flink是一个开源的分布式&#xff0c;高性能&#xff0c;高可用&#xff0c;准确的流处理框架 &#xff08;1&#xff09;分布式&#xff1a;表示flink程序可以运行在很多台机器上&#xff0c; &#xff08;2&#xff09;高性能&#xff1a;表示Flink处理性…

LabVIEW使用实时跟踪查看器调试多核应用程序

LabVIEW使用实时跟踪查看器调试多核应用程序随着多核CPU的推出&#xff0c;开发人员现在可以在LabVIEW的帮助下充分利用这项新技术的功能。并行编程在为多核CPU开发应用程序时提出了新的挑战&#xff0c;例如同步多个线程对共享内存的并发访问以及处理器关联。LabVIEW可自动处理…

基于SpringBoot+vue的无偿献血后台管理系统

基于SpringBootvue的无偿献血后台管理系统 ✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取项目下载方式&#x1f345; 一、项目背…

基于BIM技术建设的重庆来福士广场项目

1. BIM工程应用概况 1.1 工程概况 重庆来福士广场项目位于朝天门广场与解放碑之间&#xff0c;直面长江与嘉陵江交汇口。是集大型购物中心、高端住宅、办公楼、公寓式酒店和酒店为一体的综合体项目。由于本项目钢结构体量大、结构复杂&#xff0c;混凝土标号高、强度大…

树莓派centos7.9(armv7hl)安装最新版宝塔linux面板 2023-0219

内存卡或usb存储器容量建议不小于16GB 1.启用 EPEL 软件源 树莓派安装centos7.9(armv7hl)以及宝塔linux面板. 2023-2-16_mklpo147的博客-CSDN博客 2.使用gcc-6 树莓派centos7.9(armv7hl)安装并切换GCC-6版本. 2023-2-18_mklpo147的博客-CSDN博客 3.更新系统 yum install -y e…

第1讲-初步认识数据库系统(测试题总结)

一、测试题 数据库系统 包含 数据库管理系统 详细版&#xff1a; 数据库管理系统DBMS是数据管理软件&#xff0c;在用户和操作系统之间。 数据库系统DBS由数据库&#xff0c;数据库管理系统&#xff08;及其应用开发工具&#xff09;、应用程序和数据库管理员DBA组成的存储、管…

使用51单片机的GPIO输出占空比可调节的PWM波

一、前言 在一些单片机或微控制器中&#xff0c;通用GPIO可以被配置为产生PWM信号。PWM即脉冲宽度调制&#xff0c;是一种用于模拟输出的技术。它可以通过改变输出信号的脉冲宽度来控制电路中的电平&#xff0c;从而实现对电路的控制。 二、什么是PWM波&#xff1f; PWM波&a…

JavaSE-线程池(5)- 建议使用的方式

JavaSE-线程池&#xff08;5&#xff09;- 建议使用的方式 虽然JDK Executors 工具类提供了默认的创建线程池的方法&#xff0c;但一般建议自定义线程池参数&#xff0c;下面是阿里巴巴开发手册给出的理由&#xff1a; 另外Spring也提供了线程池的实现&#xff0c;比如 Thread…

Flink02:Flink快速上手(Streaming WorldCount)

一、Flink快速上手 使用 &#xff08;1&#xff09;先把Flink的开发环境配置好。 &#xff08;2&#xff09;创建maven项目&#xff1a;db_flink &#xff08;3&#xff09;首先在model中将scala依赖添加进来。 &#xff08;4&#xff09;然后创建scala目录&#xff0c;因为针…

Lesson5---NumPy科学计算库

5.1 多维数组 Python拥有出色的第三方库生态系统在机器学习中&#xff0c;需要把所有的输入数据&#xff0c;都转变为多为数组的形式。score[i, j]二维数组i,j都从0开始 score[5] [85, 72, 61, 92, 80] score[2,5] [[85, 72, 61, 92, 80],[85, 72, 61, 92, 80]] score[30,5…

Linux系统之iptables应用SNAT与DNAT

目录 SNAT 一.SNAT的原理介绍 1.应用环境 2.SNAT原理 3.SNAT转换前提条件 二.开启SNAT 1.临时打开 2.永久打开 三.SNAT的转换 1.固定的公网IP地址 2.非固定的公网IP地址(共享动态IP地址) 四.SNAT实验 1.实验环境准备 2.配置web服务器&#xff08;192.168.100.100…

测试3.测试方法的分类

3.测试分类 系统测试包括回归测试和冒烟测试 回归测试&#xff1a;修改了旧的代码后&#xff0c;重新测试功能是否正确&#xff0c;有没有引入新的错误或导致其它代码产生错误 冒烟测试&#xff1a;目的是确认软件基本功能正常&#xff0c;可以进行后续的正式测试工作 按是否…