当前位置:网站首页>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 !
边栏推荐
- QT笔记——Q_Q 和Q_D 学习
- 事半功倍:学会WEB性能测试用例设计模型
- Hello World driver (II) - primary version
- LeetCode·每日一题·919.完全二叉树插入器·层次遍历·BFS
- js中数组排序的方法有哪些
- The difference between the world wide web, the Internet and the Internet
- 2022-07-21 study notes of group 4 self-cultivation class (every day)
- canvas——绘制图片——动图制作
- Istio三之VirtualService、Gateway、DestinationRule配置使用
- Functions and usage of snownlp Library
猜你喜欢

Canvas -- draw curve -- wall clock, pie chart, five pointed star

LeetCode·
![[sql] case expression](/img/05/1bbb0b5099443f7ce5f5511703477e.png)
[sql] case expression

Opencv报错:(parameter or structure field))Unrecognized or unsupported array type in functon ‘cvGetMat‘

The difference between the world wide web, the Internet and the Internet

TCP experimental verification

Win11 hide input method status bar method

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

Multithreaded programming
![[STL]优先级队列priority_queue](/img/79/d13913cbb9d98f936a9501633b38bf.png)
[STL]优先级队列priority_queue
随机推荐
小测(一)
【无标题】
"Xiao Deng's view" the value brought by Siem to enterprises (II)
Canvas -- drawing of rectangle -- making of histogram
2020 AF-RCNN: An anchor-free convolutional neural network for multi-categoriesagricultural pest det
2022-07-21 study notes of group 4 self-cultivation class (every day)
ByteDance (Tiktok) software test monthly salary 23K post, technical two-sided interview questions are newly released
事半功倍:学会WEB性能测试用例设计模型
Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)
LoRa和NB-IOT可用用在哪些地方
论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection
YOLOv3: An Incremental Improvement
【尤里复裂人】带你轻松理解——深拷贝和浅拷贝
使用VRRP技术实现网关设备冗余,附详细配置实验
一篇文章让你理解 云原生 容器化相关
An article allows you to understand the relevance of cloud native containerization
The difference between the world wide web, the Internet and the Internet
tensorflow中tf.Variable()函数的用法
File operation (I) -- File introduction and file opening and closing methods
Why did Mr. Cao, a productionist in the field of high-end tea, choose Ruifeng L6 max?