|
|
@ -23,10 +23,12 @@ public enum ExcelTypeEnum { |
|
|
|
* csv |
|
|
|
* csv |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
CSV(".csv", new byte[] {-27, -89, -109, -27}), |
|
|
|
CSV(".csv", new byte[] {-27, -89, -109, -27}), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* xls |
|
|
|
* xls |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
XLS(".xls", new byte[] {-48, -49, 17, -32, -95, -79, 26, -31}), |
|
|
|
XLS(".xls", new byte[] {-48, -49, 17, -32, -95, -79, 26, -31}), |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* xlsx |
|
|
|
* xlsx |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -96,13 +98,11 @@ public enum ExcelTypeEnum { |
|
|
|
byte[] data = IOUtils.peekFirstNBytes(inputStream, MAX_PATTERN_LENGTH); |
|
|
|
byte[] data = IOUtils.peekFirstNBytes(inputStream, MAX_PATTERN_LENGTH); |
|
|
|
if (findMagic(XLSX.magic, data)) { |
|
|
|
if (findMagic(XLSX.magic, data)) { |
|
|
|
return XLSX; |
|
|
|
return XLSX; |
|
|
|
} else if (findMagic(CSV.magic, data)) { |
|
|
|
|
|
|
|
return CSV; |
|
|
|
|
|
|
|
} else if (findMagic(XLS.magic, data)) { |
|
|
|
} else if (findMagic(XLS.magic, data)) { |
|
|
|
return XLS; |
|
|
|
return XLS; |
|
|
|
} |
|
|
|
} |
|
|
|
throw new ExcelCommonException( |
|
|
|
// csv has no fixed prefix, if the format is not specified, it defaults to csv
|
|
|
|
"Convert excel format exception.You can try specifying the 'excelType' yourself"); |
|
|
|
return CSV; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean findMagic(byte[] expected, byte[] actual) { |
|
|
|
private static boolean findMagic(byte[] expected, byte[] actual) { |
|
|
|