導(dǎo)入依賴
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.23</version>
</dependency>
創(chuàng)建util工具包以及Excel工具類
public class ExcelUtils {
public static void PraseExcel(InputStream inputStream){
ExcelUtil.readBySax(inputStream,0,(sheetIndex,rowIndex,list) ->{
System.out.println(sheetIndex);
System.out.println(rowIndex);
System.out.println(list);
});
}
}
搭建Controller層進(jìn)行測試
@Controller
public class ExcelPraseController {
@RequestMapping("/ExcelParse")
@ResponseBody
public String pubggupload(@RequestParam("file")MultipartFile file, Model model) throws Exception{
String name=file.getOriginalFilename();
System.out.println(name);
if(!name.substring(name.length()-4).equals(".xls")){
return "格式不正確";
}
ExcelUtils.PraseExcel(file.getInputStream());
return "輸出成功";
}
}
編寫前端界面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="http://localhost:8080/ExcelParse">
<input type="file" name="file" /><input type="submit" value="上傳"/>
</form>
</body>
</html>
功能測試
后端返回數(shù)據(jù)文章來源:http://www.zghlxwxcb.cn/news/detail-808909.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-808909.html
到了這里,關(guān)于springboot-簡單測試 前端上傳Excel表格后端解析數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!