package com.chinaitop.depot.intelligent.utils;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 * @auther mafy
 * @createtime 2017/10/26 0026
 */
public class ExcelImportUtils {

    //是否是2003的excel，返回true是2003
    public static boolean isExcel2003(String filePath)  {
        return filePath.matches("^.+\\.(?i)(xls)$");
    }

    //是否是2007的excel，返回true是2007
    public static boolean isExcel2007(String filePath)  {
        return filePath.matches("^.+\\.(?i)(xlsx)$");
    }

    /**
     * 验证EXCEL文件
     * @param filePath
     * @return
     */
    public static boolean validateExcel(String filePath){
        if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))){
            return false;
        }
        return true;
    }

    public static boolean isEmpty(String type,int index,boolean[] NotEmpty){//判断是否可为空
        return NotEmpty[index];
    }

    //判断导入的excel是否和模板相同
    public  static boolean isSame(Row row, int totalCells,String[] titleArr){
        for (int i = 0; i < totalCells; i++) {
            Cell cell = row.getCell(i);//第一行的每一列
            if(!ParameterUtil.isequal(cell.getStringCellValue(),titleArr[i]) || (totalCells != titleArr.length)){
                return false;
            }
        }
        return true;
    }
}