|
@@ -141,6 +141,11 @@ public class ImportExcel {
|
|
|
this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetName);
|
|
|
}
|
|
|
|
|
|
+ public ImportExcel(MultipartFile multipartFile, int headerNum, String[] sheetName)
|
|
|
+ throws InvalidFormatException, IOException {
|
|
|
+ this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetName);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 构造函数
|
|
|
* @param path 导入文件对象
|
|
@@ -187,6 +192,30 @@ public class ImportExcel {
|
|
|
log.debug("Initialize success.");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public ImportExcel(String fileName, InputStream is, int headerNum, String[] sheetName)
|
|
|
+ throws InvalidFormatException, IOException {
|
|
|
+ int i = 0;
|
|
|
+ if (StringUtils.isBlank(fileName)){
|
|
|
+ throw new RuntimeException("导入文档为空!");
|
|
|
+ }else if(fileName.toLowerCase().endsWith("xls")){
|
|
|
+ this.wb = new HSSFWorkbook(is);
|
|
|
+ }else if(fileName.toLowerCase().endsWith("xlsx")){
|
|
|
+ this.wb = new XSSFWorkbook(is);
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("文档格式不正确!");
|
|
|
+ }
|
|
|
+ for(int j=0;j<sheetName.length;j++){
|
|
|
+ if(this.wb.getSheet(sheetName[j]) != null ){
|
|
|
+ i=j;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.sheet = this.wb.getSheet(sheetName[i]);
|
|
|
+ this.headerNum = headerNum;
|
|
|
+ log.debug("Initialize success.");
|
|
|
+ }
|
|
|
+
|
|
|
// public ImportExcel(MultipartFile file,int headerNum,String sheetName) throws IOException {
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
// InputStream is = file.getInputStream();
|