easyExcel设置行高为小数类型

步骤:

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 = contentHeight;
    }

    /**
     * 设置表头的行高
     */
    @Override
    protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
        row.setHeightInPoints((float) headHeight);
    }

    /**
     * 设置内容的行高
     */
    @Override
    protected void setContentColumnHeight(Row row, int relativeRowIndex) {
        row.setHeightInPoints((float) contentHeight);
    }

}

有了这个类后,我们只需要在生成table或sheet时,创建该对象即可,我的代码如下[设置表头行高为20.5,内容行高为14.5]

WriteTable dataTable = EasyExcel.writerTable(3).registerWriteHandler( new CustomRowHeightStyleStrategy(20.5, 14.5)).head(head).build();

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

睡竹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值