判断导入的Excel表是2003还是2007
public static Workbook getWorkBook(MultipartFile file) {
String filename = file.getOriginalFilename();
Workbook workbook = null;
try (InputStream ins = file.getInputStream()) {
if (filename.toLowerCase().endsWith("xls")) {
workbook = new HSSFWorkbook(ins);
System.out.println("2003及以下");
} else if (filename.toLowerCase().endsWith("xlsx")) {
workbook = new XSSFWorkbook(ins);
System.out.println("2007及以上");
}
} catch (IOException e) {
e.printStackTrace();
}
return workbook;
}
public static Workbook getWorkBook(File file) {
String filename = file.getName();
Workbook workbook = null;
try (InputStream ins = new FileInputStream(file)) {
if (filename.toLowerCase().endsWith("xls")) {
workbook = new HSSFWorkbook(ins);
System.out.println("2003及以下");
} else if (filename.toLowerCase().endsWith("xlsx")) {
workbook = new XSSFWorkbook(ins);
System.out.println("2007及以上");
}
} catch (IOException e) {
e.printStackTrace();
}
return workbook;
}