package com.sysu.admin.controller.crop.xls;

import com.alibaba.excel.metadata.*;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author shixiaohao
 * @Date 2020/10/28 18:18
 * @Description: CustemHandler
 */
public class CustomHandler extends AbstractColumnWidthStyleStrategy {

    private static final int MAX_COLUMN_WIDTH = 3000;

    public CustomHandler() {
    }

    @Override
    protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, org.apache.poi.ss.usermodel.Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        if (isHead) {
            // 所有是head的cell设置固定的宽度 MAX_COLUMN_WIDTH
            if(head.getFieldName().equals("address") || head.getFieldName().equals("name")){
                writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 10000);
            }else {
                writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), MAX_COLUMN_WIDTH);
            }
            // 设置默认行高
            // writeSheetHolder.getCachedSheet().setDefaultRowHeightInPoints();
        }
    }

}
