package com.stylefeng.guns.modular.system.utils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; public class WoUtil { public static Workbook ImportFile(MultipartFile importFile) { Workbook book = null; if(importFile == null) { //throw new WoException(SysConstant.ERR_EXCEL_NULL); } String fileName = importFile.getOriginalFilename(); try { if(fileName.endsWith(".xlsx")) //当表格的后缀是".xlsx时" { book = new XSSFWorkbook(importFile.getInputStream()); }else { book = new HSSFWorkbook(importFile.getInputStream()); } } catch (IOException e) { //throw new WoException(e,SysConstant.ERR_EXCEL_NO); } return book; } }