diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java b/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java index 34c584e8..861cd91c 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java @@ -59,12 +59,6 @@ public enum ExcelTypeEnum { if (!file.exists()) { throw new ExcelAnalysisException("File " + file.getAbsolutePath() + " not exists."); } - // If there is a password, use the FileMagic first - if (!StringUtils.isEmpty(readWorkbook.getPassword())) { - try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) { - return recognitionExcelType(bufferedInputStream); - } - } // Use the name to determine the type String fileName = file.getName(); if (fileName.endsWith(XLSX.getValue())) { @@ -74,6 +68,10 @@ public enum ExcelTypeEnum { } else if (fileName.endsWith(CSV.getValue())) { return CSV; } + //If cannot get the name, use the magic number to determine the type + try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) { + return recognitionExcelType(bufferedInputStream); + } } if (!inputStream.markSupported()) { inputStream = new BufferedInputStream(inputStream);