88import cn .idev .excel .exception .ExcelAnalysisException ;
99import cn .idev .excel .exception .ExcelCommonException ;
1010import cn .idev .excel .read .metadata .ReadWorkbook ;
11+ import cn .idev .excel .util .StringUtils ;
12+
1113import lombok .Getter ;
1214import org .apache .poi .util .IOUtils ;
1315
@@ -57,6 +59,12 @@ public static ExcelTypeEnum valueOf(ReadWorkbook readWorkbook) {
5759 if (!file .exists ()) {
5860 throw new ExcelAnalysisException ("File " + file .getAbsolutePath () + " not exists." );
5961 }
62+ // If there is a password, use the FileMagic first
63+ if (!StringUtils .isEmpty (readWorkbook .getPassword ())) {
64+ try (BufferedInputStream bufferedInputStream = new BufferedInputStream (new FileInputStream (file ))) {
65+ return recognitionExcelType (bufferedInputStream );
66+ }
67+ }
6068 // Use the name to determine the type
6169 String fileName = file .getName ();
6270 if (fileName .endsWith (XLSX .getValue ())) {
@@ -66,8 +74,10 @@ public static ExcelTypeEnum valueOf(ReadWorkbook readWorkbook) {
6674 } else if (fileName .endsWith (CSV .getValue ())) {
6775 return CSV ;
6876 }
69- try (BufferedInputStream bufferedInputStream = new BufferedInputStream (new FileInputStream (file ))) {
70- return recognitionExcelType (bufferedInputStream );
77+ if (StringUtils .isEmpty (readWorkbook .getPassword ())) {
78+ try (BufferedInputStream bufferedInputStream = new BufferedInputStream (new FileInputStream (file ))) {
79+ return recognitionExcelType (bufferedInputStream );
80+ }
7181 }
7282 }
7383 if (!inputStream .markSupported ()) {
0 commit comments