LearnController.java
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.jevon.controller;
import com.jevon.model.*;
import com.jevon.vo.BaseVo;
import com.jevon.vo.req.InitAnalyseReqVo;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
/**
* @author chen
* @version 1.0
* @date 2019/10/17 0017 13:33
*/
@RestController
@RequestMapping(value = "/learn")
@Api(value = "学情分析")
public class LearnController {
public BaseVo initAnalyse(@RequestBody InitAnalyseReqVo initAnalyseReqVo){
BaseVo baseVo = new BaseVo();
Date date = new Date();
try{
String fileUrl = initAnalyseReqVo.getUrl();
File excelFile = new File(fileUrl);
// 获得工作簿
String file = excelFile.getName();
Workbook workbook = null;
if (file.endsWith("xls")) {
workbook = new HSSFWorkbook(new FileInputStream(excelFile));
} else {
workbook = new XSSFWorkbook(new FileInputStream(excelFile));
}
// 获得工作表
Sheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
int column = 0 ;
int courseNumber = 0;
for (int i = 0; i < rows; i++) {
// 获取第i行数据
Row sheetRow = sheet.getRow(i);
if (i == 0) {
//获取标题
String title = sheetRow.getCell(0).getStringCellValue().trim();
}else if(i == 1){
//获取表头
int j = 0 ;
while (sheetRow.getCell(j) != null && StringUtils.isNotBlank(sheetRow.getCell(j).getStringCellValue().trim())) {
j++ ;
}
column = j ;
} else {
for (int j = 0; j < column; j++) {
Cell cell = sheetRow.getCell(j);
if(cell != null){
cell.setCellType(CellType.STRING);
}
}
}
}
}catch (Exception e){
System.out.println(e);
baseVo.setSuccess(false);
}
return baseVo;
}
}