当前位置: 首页 > news >正文

easyExcel 写复杂表头

写模板

模板图片:
在这里插入图片描述
实体类(这里没有用@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;@ExcelIgnoreprivate String projectName;@ExcelIgnoreprivate 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;}

相关文章:

easyExcel 写复杂表头

写模板 模板图片&#xff1a; 实体类&#xff08;这里没有用Data 是因为Lombok和easyExcal的版本冲突&#xff0c;在导入读取的时候获取不到值&#xff09; package cn.iocoder.yudao.module.project.controller.admin.goods.vo;import com.alibaba.excel.annotation.ExcelI…...

关于线程池的执行流程和拒绝策略

使用线程池的好处为&#xff1a; 降低资源消耗&#xff1a;减少线程的创建和销毁带来的性能开销。 提高响应速度&#xff1a;当任务来时可以直接使用&#xff0c;不用等待线程创建 可管理性&#xff1a; 进行统一的分配&#xff0c;监控&#xff0c;避免大量的线程间因互相抢…...

【李忍考研传】二、约定

因为收学生证用了好些时间&#xff0c;李忍把学生证都交给班长后&#xff0c;就赶忙跑去食堂。远远地&#xff0c;他就看到那个瘦小的身影立在食堂正门前&#xff0c;那是他们约定每天午餐集合的地方。 “你咋这么慢啊……” “害&#xff01;帮班长收东西耽误了点时间&#…...

2023-2-19 刷题情况

修改两个元素的最小分数 题目描述 给你一个下标从 0 开始的整数数组 nums 。 nums 的 最小 得分是满足 0 < i < j < nums.length 的 |nums[i] - nums[j]| 的最小值。nums的 最大 得分是满足 0 < i < j < nums.length 的 |nums[i] - nums[j]| 的最大值。nu…...

LeetCode笔记:Weekly Contest 333

LeetCode笔记&#xff1a;Weekly Contest 333 1. 题目一 1. 解题思路2. 代码实现 2. 题目二 1. 解题思路2. 代码实现 3. 题目三 1. 解题思路2. 代码实现 4. 题目四 比赛链接&#xff1a;https://leetcode.com/contest/weekly-contest-333 1. 题目一 给出题目一的试题链接如下…...

元数据管理 1

1、关于元数据管理原则说法正确的是 (知识点: 三月份模拟题)A.确保员工了解如何访问和使用元数据。B.制定、实施和审核元数据标准&#xff0c;以简化元数据的集成和使用。C.创建反馈机制&#xff0c;以便数据使用者可以将错误或过时的元数据反馈给元数据管理团队。D.以上都对正…...

统计二进制中比特1的个数

快速统计比特1的数量int CountBitOnes(int32_t n) {int result 0;for(;n;result) {n & n-1;}return result; }原理很简单&#xff0c;n-1会将n中最靠近结尾的1减一&#xff0c;这样n&n-1&#xff0c;n中最靠近结尾的1就变成了0&#xff1b;假设n 0b xxxxxxxx100n - 1…...

第三方实现跑马灯和手写实现跑马灯

目录第三方实现跑马灯手写实现跑马灯手写实现跑马灯【整体代码】自己细心研究一下上述代码第三方实现跑马灯 https://vue3-marquee.vercel.app/guide.html#changes-from-v2https://evodiaaut.github.io/vue-marquee-text-component/ 手写实现跑马灯 CSS部分 <style>.m…...

React Native Cannot run program “node“问题

概述 前几天mac重装系统了&#xff0c;用Android studio重新构建React native项目时&#xff0c;报Cannot run program "node"错误。 电脑系统为macOS 12.6.3 (Monterey)&#xff0c;M1 Pro芯片。设备信息如下图所示&#xff1a; 完整错误信息如下图所示&#xff…...

python基于vue微信小程序 房屋租赁出租系统

目录 1 绪论 1 1.1课题背景 1 1.2课题研究现状 1 1.3初步设计方法与实施方案 2 1.4本文研究内容 2 2 系统开发环境 4 2.1 2.2MyEclipse环境配置 4 2.3 B/S结构简介 4 2.4MySQL数据库 5 2. 3 系统分析 6 3.1系统可行性分析 6 3.1.1经济可行性 6 3.1.2技术可行性 6 3.1.3运行可行…...

ThreadPoolExecutor管理异步线程笔记

为什么使用线程池&#xff1f; 线程的创建和销毁都需要不小的系统开销&#xff0c;不加以控制管理容易发生OOM错误。避免线程并发抢占系统资源导致系统阻塞。具备一定的线程管理能力&#xff08;数量、存活时间&#xff0c;任务管理&#xff09; new ThreadPoolExecutor(int …...

MotoSimEG-VRC教程:动态输送带创建以及示教编程与仿真运行

目录 任务描述 简易输送带外部设备创建 输送带模型添加与配置 工件安装到输送带 输送带输送工件程序编写与仿真运行 任务描述 在MotoSimEG-VRC中创建1条输送带&#xff0c;并且能够实现将工件从输送带起始点位置处输送到结束点位置处。 简易输送带外部设备创建 在MotoS…...

PyTorch 并行训练 DistributedDataParallel完整代码示例

使用大型数据集训练大型深度神经网络 (DNN) 的问题是深度学习领域的主要挑战。 随着 DNN 和数据集规模的增加&#xff0c;训练这些模型的计算和内存需求也会增加。 这使得在计算资源有限的单台机器上训练这些模型变得困难甚至不可能。 使用大型数据集训练大型 DNN 的一些主要挑…...

Golang实现ttl机制保存内存数据

ttl(time-to-live) 数据存活时间&#xff0c;我们这里指数据在内存中保存一段时间&#xff0c;超过期限则不能被读取到&#xff0c;与Redis的ttl机制类似。本文仅实现ttl部分&#xff0c;不考虑序列化和反序列化。 获取当前时间 涉及时间计算&#xff0c;这里首先介绍如何获取…...

js中数字运算结果与预期不一致的问题和解决方案

本文主要是和大家聊聊关于js中经常出现数字运算结果与预期结果不一致的问题&#xff0c;与及解决该问题的的方案。 一、问题现象 如&#xff1a;0.1 0.2的预期结果是0.3&#xff0c;但是在js中得到的计算结果却是0.30000000000000004&#xff0c;如下图所示 如&#xff1a;0…...

C++ Primer Plus 学习笔记(一)——基本类型

字节与字符 计算机内存的基本单位是位&#xff08;bit&#xff09;&#xff0c;字节&#xff08;byte&#xff09;通常指的是8位的内存单元&#xff0c;从这个意义上来说&#xff0c;字节指的就是描述计算机内存量的度量单位。 C对字节的定义则有些不同&#xff0c;C字节由至…...

ChatGpt与Google 谁能给出最好的回答

ChatGPT由于其先进的会话和技术功能而越来越受欢迎。你可以问聊天机器人任何你想问的问题&#xff0c;它会在几秒钟内输出答案。虽然它不是一个搜索引擎&#xff0c;你应该使用ChatGPT作为你的信息来源而不是谷歌&#xff0c;百度吗? 我们来根据国外的一场测试来看一下 ChatG…...

【Redis】一、CentOS64 安装 Redis

1.下载redis https://download.redis.io/releases/2.将 redis 安装包拷贝到 /opt/ 目录 最好自己创建一个文件夹 3.解压 tar -zvxf redis-6.2.1.tar.gz4. 安装gcc yum install gcc5. 进入目录 cd /opt/redis/redis-6.2.1/6. 编译 make7.执行 make install 进行安装 8. …...

Redis底层原理(持久化+分布式锁)

Redis底层原理 持久化 Redis虽然是个内存数据库&#xff0c;但是Redis支持RDB和AOF &#xff08;Redis Database Backup file&#xff08;Redis数据备份文件&#xff09;&#xff0c;也被叫做Redis数据快照。简单来说就是把内存中的所有数据都记录到磁盘中 &#xff1b;Appen…...

Spring Cloud Nacos实战(八) - Nacos集群配置

Nacos集群配置 更改Nacos启动命令配置原理 我们现在知道&#xff0c;想要启动Naocs只需要启动startup.sh命令即可&#xff0c;但是如果启动3个Nacos那&#xff1f;所以如果我们需要启动多个Nacos&#xff0c;其实Nacos本身默认启动就是集群模式。 注意点&#xff1a;如果是l…...

在rocky linux 9.5上在线安装 docker

前面是指南&#xff0c;后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...

条件运算符

C中的三目运算符&#xff08;也称条件运算符&#xff0c;英文&#xff1a;ternary operator&#xff09;是一种简洁的条件选择语句&#xff0c;语法如下&#xff1a; 条件表达式 ? 表达式1 : 表达式2• 如果“条件表达式”为true&#xff0c;则整个表达式的结果为“表达式1”…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

【论文笔记】若干矿井粉尘检测算法概述

总的来说&#xff0c;传统机器学习、传统机器学习与深度学习的结合、LSTM等算法所需要的数据集来源于矿井传感器测量的粉尘浓度&#xff0c;通过建立回归模型来预测未来矿井的粉尘浓度。传统机器学习算法性能易受数据中极端值的影响。YOLO等计算机视觉算法所需要的数据集来源于…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

Java毕业设计:WML信息查询与后端信息发布系统开发

JAVAWML信息查询与后端信息发布系统实现 一、系统概述 本系统基于Java和WML(无线标记语言)技术开发&#xff0c;实现了移动设备上的信息查询与后端信息发布功能。系统采用B/S架构&#xff0c;服务器端使用Java Servlet处理请求&#xff0c;数据库采用MySQL存储信息&#xff0…...

CRMEB 中 PHP 短信扩展开发:涵盖一号通、阿里云、腾讯云、创蓝

目前已有一号通短信、阿里云短信、腾讯云短信扩展 扩展入口文件 文件目录 crmeb\services\sms\Sms.php 默认驱动类型为&#xff1a;一号通 namespace crmeb\services\sms;use crmeb\basic\BaseManager; use crmeb\services\AccessTokenServeService; use crmeb\services\sms\…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...

前端中slice和splic的区别

1. slice slice 用于从数组中提取一部分元素&#xff0c;返回一个新的数组。 特点&#xff1a; 不修改原数组&#xff1a;slice 不会改变原数组&#xff0c;而是返回一个新的数组。提取数组的部分&#xff1a;slice 会根据指定的开始索引和结束索引提取数组的一部分。不包含…...

pycharm 设置环境出错

pycharm 设置环境出错 pycharm 新建项目&#xff0c;设置虚拟环境&#xff0c;出错 pycharm 出错 Cannot open Local Failed to start [powershell.exe, -NoExit, -ExecutionPolicy, Bypass, -File, C:\Program Files\JetBrains\PyCharm 2024.1.3\plugins\terminal\shell-int…...