步骤:
1>新建一个类,继承AbstractRowHeightStyleStrategy类
2>重写setHeadColumnHeight方法【设置表格头部行高】和setContentColumnHeight方法【设置内容行高】
3>调用row.setHeightInPoints()直接设置行高
4>在业务代码中,easyExcel生成sheet对象或生成table对象时,创建该对象即可
具体代码如下:
我自定义一个类,名字为:CustomRowHeightStyleStrategy,为了灵活,我把行高的数据定义在构造方法中
import org.apache.poi.ss.usermodel.Row;
import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
/**
* excel表格的行高设置
*
* @author 睡竹
* @date 2022年5月23日
* @telephone 15570718318
*/
public class CustomRowHeightStyleStrategy extends AbstractRowHeightStyleStrategy {
// 表头的行高
double headHeight;
// 内容的行高
double contentHeight;
public CustomRowHeightStyleStrategy(double headHeight, double contentHeight) {
this.headHeight = headHeight;
this.contentHeight
自定义Excel行高设置

本文介绍了如何通过创建自定义类`CustomRowHeightStyleStrategy`,继承`AbstractRowHeightStyleStrategy`来设置Excel表格的头部和内容行高。在类中,重写了`setHeadColumnHeight`和`setContentColumnHeight`方法,使用`row.setHeightInPoints()`来直接设置行高。在实际业务代码中,使用`EasyExcel`生成表格时,通过创建此类实例并传入行高参数即可实现定制行高。例如,设置表头行高为20.5,内容行高为14.5。
最低0.47元/天 解锁文章
7559

被折叠的 条评论
为什么被折叠?



