zouyu
3 天以前 2ea3b36a810adcb639f4d3c72c860f722f601927
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.ruoyi.common.utils.excel;
 
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Row;
 
/**
 * 表头、内容行 自定义不同行高
 */
public class HeaderContentRowHeightHandler implements RowWriteHandler {
    private final float headerHeight; // 表头行高(磅)
    private final float contentHeight; // 内容行高(磅)
    private final int headerRowCount; // 表头行数(层级数)
 
    /**
     * @param headerHeight 表头行高
     * @param contentHeight 内容行高
     * @param headerRowCount 表头行数(动态表头的层级数)
     */
    public HeaderContentRowHeightHandler(float headerHeight, float contentHeight, int headerRowCount) {
        this.headerHeight = headerHeight;
        this.contentHeight = contentHeight;
        this.headerRowCount = headerRowCount;
    }
 
    @Override
    public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Boolean isHead) {
        // 判断:行索引 < 表头行数 → 表头行
        if (rowIndex < headerRowCount) {
            row.setHeight((short) (headerHeight * 20));
        } else {
            row.setHeight((short) (contentHeight * 20));
        }
    }
}