|
@@ -99,6 +99,11 @@ public class ImportExcel {
|
|
|
throws InvalidFormatException, IOException {
|
|
|
this(new File(fileName), headerNum, sheetIndex);
|
|
|
}
|
|
|
+
|
|
|
+ public ImportExcel(String fileName, int headerNum, String sheetName)
|
|
|
+ throws InvalidFormatException, IOException {
|
|
|
+ this(new File(fileName), headerNum, sheetName);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -112,6 +117,11 @@ public class ImportExcel {
|
|
|
throws InvalidFormatException, IOException {
|
|
|
this(file.getName(), new FileInputStream(file), headerNum, sheetIndex);
|
|
|
}
|
|
|
+
|
|
|
+ public ImportExcel(File file, int headerNum, String sheetName)
|
|
|
+ throws InvalidFormatException, IOException {
|
|
|
+ this(file.getName(), new FileInputStream(file), headerNum, sheetName);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -121,9 +131,14 @@ public class ImportExcel {
|
|
|
* @throws InvalidFormatException
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetIndex)
|
|
|
+ public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetName)
|
|
|
throws InvalidFormatException, IOException {
|
|
|
- this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex);
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -134,7 +149,7 @@ public class ImportExcel {
|
|
|
* @throws InvalidFormatException
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
|
|
|
+ public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
|
|
|
throws InvalidFormatException, IOException {
|
|
|
if (StringUtils.isBlank(fileName)){
|
|
|
throw new RuntimeException("导入文档为空!");
|
|
@@ -152,6 +167,39 @@ public class ImportExcel {
|
|
|
this.headerNum = headerNum;
|
|
|
log.debug("Initialize success.");
|
|
|
}
|
|
|
+
|
|
|
+ public ImportExcel(String fileName, InputStream is, int headerNum, String sheetName)
|
|
|
+ throws InvalidFormatException, IOException {
|
|
|
+ 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("文档格式不正确!");
|
|
|
+ }
|
|
|
+ this.sheet = this.wb.getSheet(sheetName);
|
|
|
+ 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();
|
|
|
+// 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("文档格式不正确!");
|
|
|
+// }
|
|
|
+// this.sheet = this.wb.getSheet(sheetName);
|
|
|
+// this.headerNum = headerNum;
|
|
|
+// log.debug("Initialize success.");
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 获取行对象
|