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));
|
}
|
}
|
}
|