package com.tiesheng.poi.write;

import cn.hutool.core.util.ClassUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import com.alibaba.excel.support.ExcelTypeEnum;

import java.util.List;

/**
 * @author hao
 */
@HeadRowHeight(24)
@HeadFontStyle(fontHeightInPoints = 13)
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT)
@ContentRowHeight(20)
@ContentFontStyle(fontHeightInPoints = 12)
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER)
@ColumnWidth(20)
public class PoiWriteBase {


    /**
     * 导出数据
     *
     * @param list
     * @return
     */
    public static <T> boolean export(List<T> list, String absPath, String sheetName) {
        Class<?> aClass = ClassUtil.getTypeArgument(list.getClass(), 0);
        EasyExcel.write(absPath, aClass).excelType(ExcelTypeEnum.XLSX)
                .sheet(sheetName)
                .doWrite(list);
        return true;
    }

}
