zqy
2024-09-23 b255f2a8bb78bb5197c8b839853682203c8a1ddc
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -24,6 +24,8 @@
import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
@@ -428,6 +430,11 @@
                    {
                        if (val instanceof String)
                        {
                            System.out.println("====++++++++");
                            System.out.println(val);
                            if(((String) val).contains("/"))
                                val = ((String) val).replace("/","-");
                            System.out.println(val);
                            val = DateUtils.parseDate(val);
                        }
                        else if (val instanceof Double)
@@ -1569,8 +1576,10 @@
        for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++)
        {
            Cell cell = row.getCell(i);
            if (cell != null && cell.getCellType() != CellType.BLANK)
//            System.out.println("11111111111111:/"+(cell != null)+"\n2222222222:/"+cell+"\n333333:/"+String.valueOf(cell).length());
            if (cell != null && cell.getCellType() != CellType.BLANK && !cell.toString().equals(""))
            {
//                System.out.println("444444+/"+(cell.getCellType()));
                return false;
            }
        }
@@ -1731,4 +1740,38 @@
        }
        return method;
    }
    /**
     * 对excel表单默认第一个索引名转换成list(EasyExcel)
     *
     * @param is 输入流
     * @return 转换后集合
     */
    public List<T> importEasyExcel(InputStream is) throws Exception
    {
        return EasyExcel.read(is).head(clazz).sheet().doReadSync();
    }
    /**
     * 对list数据源将其里面的数据导入到excel表单(EasyExcel)
     *
     * @param list 导出数据集合
     * @param sheetName 工作表的名称
     * @return 结果
     */
    public void exportEasyExcel(HttpServletResponse response, List<T> list, String sheetName)
    {
        try
        {
            EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(list);
        }
        catch (IOException e)
        {
            log.error("导出EasyExcel异常{}", e.getMessage());
        }
    }
}