8
8
import cn .idev .excel .exception .ExcelAnalysisException ;
9
9
import cn .idev .excel .exception .ExcelCommonException ;
10
10
import cn .idev .excel .read .metadata .ReadWorkbook ;
11
+ import cn .idev .excel .util .StringUtils ;
12
+
11
13
import lombok .Getter ;
12
14
import org .apache .poi .util .IOUtils ;
13
15
@@ -57,6 +59,12 @@ public static ExcelTypeEnum valueOf(ReadWorkbook readWorkbook) {
57
59
if (!file .exists ()) {
58
60
throw new ExcelAnalysisException ("File " + file .getAbsolutePath () + " not exists." );
59
61
}
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
+ }
60
68
// Use the name to determine the type
61
69
String fileName = file .getName ();
62
70
if (fileName .endsWith (XLSX .getValue ())) {
@@ -66,8 +74,10 @@ public static ExcelTypeEnum valueOf(ReadWorkbook readWorkbook) {
66
74
} else if (fileName .endsWith (CSV .getValue ())) {
67
75
return CSV ;
68
76
}
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
+ }
71
81
}
72
82
}
73
83
if (!inputStream .markSupported ()) {
0 commit comments