package com.friday.custody.utils;

import com.friday.custody.exception.RRException;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;


@Slf4j
public class ExcelWriteUtil {
    private static final List<String> EXCEL_SUFFIX = Arrays.asList("xls", "xlsx");

    /**
     *
     * @param fis
     * @return
     * @throws IOException
     */
    public static Workbook getWorkbook(InputStream fis){
        try {
            Workbook wb = WorkbookFactory.create(fis);
            return wb;
        } catch (Exception e) {
            log.error("getWorkbook:Exception:", e);
            throw new RRException("文件为空请重新上传");
        }
    }

    public static boolean writeExcelFile(Workbook workbook) {

        return false;
    }

    public static CellStyle getCellStyle(Workbook workbook, String fontName, short color) {
        CellStyle cellStyle = getCellStyle(workbook);
        Font font = workbook.createFont();
        font.setFontName(fontName);
        font.setColor(color);
        cellStyle.setFont(font);
        return cellStyle;
    }
    /**
     * @author K0050148
     * @date 2020/6/25 21:43
     * @param workbook
     * @description 获取单元格样式
     * @return void
     */
    public static CellStyle getCellStyle(Workbook workbook) {
        CellStyle cellStyle = workbook.createCellStyle();
//        cellStyle.setBorderBottom(BorderStyle.THIN); // 底部边框
//        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); // 底部边框颜色
//        cellStyle.setBorderTop(BorderStyle.THIN);  // 左边边框
//        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); // 上边边框颜色
//        cellStyle.setBorderLeft(BorderStyle.THIN); //左边边框
//        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); //左边边框颜色
//        cellStyle.setBorderRight(BorderStyle.THIN); //右边边框
////        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); //右边边框颜色
//        cellStyle.setAlignment(HorizontalAlignment.CENTER); //水平居中
//        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //垂直居中
        cellStyle.setLocked(false); //解锁单元格
        return cellStyle;
    }

}

