1.读取网络路径的Excel文件(流文件格式)
2.获取Excel的每一行数据,并验证学校班级是否存在,并获取对应的schoolID和classID
3.批量保存学生信息,并返回保存成功的行数
导入关于Excel的Pom文件
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
测试过程中发现bug:
1、表格数据容易出现前后空格,居中显示时,对数据核查出现失误,故需要对表格数据使用trim()去除数据的前后空格。
2、表格数据为纯数字时,获取表格会默认类型为number,此时需要获取String会报“Cannot get a STRING value from a NUMERIC cell”错,需要提前使用 c0.setCellType(CellType.STRING); 详情见下面代码。
int HttpResult;
try {
logger.debug("studentExcelImport Excel fileUrl:{}", fileUrl);
URL url = new URL(fileUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // 试图连接并取得返回状态码
HttpResult = conn.getResponseCode();
if(HttpResult != HttpURLConnection.HTTP_OK) {
logger.debug("studentExcelImport Excel HttpResult:{}",<