当前位置:网站首页>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 !
边栏推荐
- Execution process behind shell commands
- An article allows you to understand the relevance of cloud native containerization
- Cloud native guide what is cloud native infrastructure
- MPLS基础实验配置
- LeetCode·
- Canvas - ECG design and how to clean the canvas
- snownlp库各功能及用法
- els 初始化窗口类
- tf.truncated_normal()用法
- How to close the case prompt icon of win11? Closing method of win11 case prompt Icon
猜你喜欢

班级里有一群学生考试结果出来了,考了语文和数学两门,请筛选出总分是第一的同学
![[STL]优先级队列priority_queue](/img/79/d13913cbb9d98f936a9501633b38bf.png)
[STL]优先级队列priority_queue

How to correctly calculate the CPU utilization of kubernetes container

ext4、ntfs、xfs、btrfs、zfs、f2fs和reiserFS性能对比

Use Anaconda to configure the tensorflow of GPU Version (less than 30 series graphics cards)

Opencv error: (parameter or structure field)) unrecognized or unsupported array type in functon 'cvgetmat‘
![[Yuri crack man] brings you easy understanding - deep copy and shallow copy](/img/26/b7330c7f5fdac55c8f5e9fa24658ee.png)
[Yuri crack man] brings you easy understanding - deep copy and shallow copy

canvas——绘制文本——饼图的修改

Looking at the next step of BAIC bluevale through the 8billion fund-raising, product upgrading and building core capabilities are the key words

LoRa和NB-IOT可用用在哪些地方
随机推荐
一篇文章让你理解 云原生 容器化相关
离线数据仓库从0到1-阶段一资源购买配置
事半功倍:学会WEB性能测试用例设计模型
The difference between the world wide web, the Internet and the Internet
Multithreaded programming
Opencv 以指定格式保存图片
tf.truncated_normal()用法
easyExcel设置行隐藏,解决setHidden(true)失效问题
[NOIP2001 普及组]装箱问题
How to close the case prompt icon of win11? Closing method of win11 case prompt Icon
STM32 - serial port learning notes (one byte, 16 bit data, string, array)
Service gateway (zuul)
Use eventlog analyzer for log forensics analysis
复制列表时踩过的坑:浅拷贝与深拷贝
Etcdv3 actual combat (III) -prevkv description and related operations
Docker installs redis!!! (including detailed illustration of each step) actual combat
QT signal transmission between multi-level objects signal transmission between multi-level nested class objects
What is the difference between heap memory and stack memory?
在混合云中管理数据库:八个关键注意事项
LoRa和NB-IOT可用用在哪些地方