当前位置:网站首页>Easyexcel sets row hiding to solve the problem of sethidden (true) invalidation
Easyexcel sets row hiding to solve the problem of sethidden (true) invalidation
2022-07-26 03:19:00 【Sleeping bamboo】
1、 Preface
easyExcel Provides a way , as follows :
WriteCellStyle.setHidden(true);
Set the cell as hidden
however , This method does not work !GitHub There is no corresponding source code on ... Friends who can directly use this method to achieve the effect are troublesome d once
2、 Realize the principle of line hiding
easyExcel The bottom is POI, therefore ,easyExcel Set hidden style , It's also inseparable from POI Of , In the view POI Source code , Find out , Set behavior hide style , In fact, set the row height to 0, We are Excel You can also know , Hide rows , In fact, line height is for 0, as follows :
【 The first 8 Rows are set to hidden , Line height for 0】

Implementation principle : Put the lines that need to be hidden , Row height set to 0 that will do
3、 The code is as follows
easyExcel You can use the following code , Set row height for header and content respectively :
// Set the row height of the data table Parameters 1 Indicates the height of the header row , Parameters 2 Indicates the content line height
SimpleRowHeightStyleStrategy rowHeightStrategy3 = new SimpleRowHeightStyleStrategy((short)20, (short) 18);however , In development , This object does not meet our needs
for example : When you need to set the last behavior to hide , This class cannot achieve this effect
If a column is set as hidden style , You can add custom tool classes , as follows :
3.1、 Custom line style tool class code
package com.shuizhu.util;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
/**
* excel Table row height setting and style
*
* @author Sleeping bamboo
*/
public class CustomRowHeightStyleStrategy extends AbstractRowHeightStyleStrategy {
/**
* Set the line number to be hidden
*/
Integer rowNum;
public CustomRowHeightStyleStrategy(int rowNum){
this.rowNum = rowNum;
}
/**
* Set the row height of the header
*/
@Override
protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
// Set the header row height to 18
row.setHeightInPoints(18);
}
/**
* Set the line height of the content relativeRowIndex Is the number of rows , Index from 0 Start
*/
@Override
protected void setContentColumnHeight(Row row, int relativeRowIndex) {
if (relativeRowIndex + 1 == rowNum) {
// Set row hiding
row.setHeightInPoints((0));
}
}
}
explain :
There are 2 A key point :
- rowNum: Line number , Which row needs to be hidden , We can just pass the serial number of the line , for example , Our tabular data total 5 That's ok 【 The total number of rows can be passed Java Code acquisition 】, You need to put the number 5 Line hiding , We deliver 5 That's all right.
- relativeRowIndex: Line number , protected void setContentColumnHeight Method will execute N Time 【N = Total rows of table data 】
When building tables , Just pass the corresponding number of lines :

I hid the first 5 That's ok , Let's see the effect :
Section of the form 5 Line hidden !
边栏推荐
- LeetCode·83双周赛·6128.最好的扑克手牌·模拟
- Understand preloading and lazy loading, and learn slow animation
- Opening method of win11 microphone permission
- 记一次SQL优化
- What's good for starting a business with 10000 yuan? Is we media OK?
- Win11 hide input method status bar method
- NFT is beautiful because it is meaningless
- els 窗口设置、WM_CREATE、WM_PAINT
- snownlp库各功能及用法
- GoLang 抽奖系统 设计
猜你喜欢

JVM内存模型解析

STM32 - PWM learning notes

LoRa无线网关如何快速实现端到云的传输

如何正确计算 Kubernetes 容器 CPU 使用率

复制列表时踩过的坑:浅拷贝与深拷贝

STM32 - DMA notes

使用VRRP技术实现网关设备冗余,附详细配置实验

论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection

Leetcode · daily question · 919. complete binary tree inserter · hierarchy traversal · BFS

Alibaba Sentinel - 集群流量控制
随机推荐
[noip2001 popularization group] the problem of maximum common divisor and minimum common multiple
Use eventlog analyzer for log forensics analysis
ELS window settings, WM_ CREATE、WM_ PAINT
Leetcode · daily question · 919. complete binary tree inserter · hierarchy traversal · BFS
ext4、ntfs、xfs、btrfs、zfs、f2fs和reiserFS性能对比
ELS callback function, exit message
图解LeetCode——5. 最长回文子串(难度:中等)
一篇文章让你理解 云原生 容器化相关
YOLOv3: An Incremental Improvement
Course notes of single chip microcomputer principle and interface technology for migrant workers majoring in electronic information engineering
称霸薪酬榜!什么行业大有“钱”途?
QT笔记——Q_Q 和Q_D 学习
Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))
GoLang 抽奖系统 设计
STM32——PWM学习笔记
LeetCode·每日一题·剑指 Offer || 115.重建序列·拓扑排序
Swin Transformer【Backbone】
Canvas -- drawing of rectangle -- making of histogram
Looking at the next step of BAIC bluevale through the 8billion fund-raising, product upgrading and building core capabilities are the key words
论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection