一、引入maven依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
二、controller层
@RequestMapping(value = "/importWorkExcel", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
public void importWorkExcel(@RequestParam("excel") MultipartFile multipartFile) throws BusinessException,IOException, ParseException {
workSpotService.importWorkExcel(multipartFile);
}
三、serviceImpl层
@Override
public void importWorkExcel(MultipartFile file) throws IOException, ParseException {
checkFile(file);
Workbook workbook = getWorkBook(file);
if(workbook != null){
for(int sheetNum = 0;sheetNum < workbook.getNumberOfSheets();sheetNum++){
Sheet sheet = workbook.getSheetAt(sheetNum);
if(sheet == null){
continue;
}
int firstRowNum = sheet.getFirstRowNum();
int lastRowNum = sheet.getLastRowNum();
for(int rowNum = firstRowNum+2;rowNum <= lastRowNum;rowNum++){
Row row = sheet.getRow(rowNum);
if(row == null){
continue;
}
int firstCellNum = row.getFirstCellNum();
int lastCellNum = row.getPhysicalNumberOfCells();
String workName = "";
String leaderName = "";
Integer leaderId = null;
Date startTime = null;
Date endTime = null;
String levelStr = "";
Integer level = null;
String majorStr = "";
Integer major = null;
for(int cellNum = 0; cellNum<row.