直接上代码:
// excel导入
@CrossOrigin
@PostMapping(value = "/batch_sms_send/parseExcel", produces = {"application/json;charset=UTF-8"})
public void parseExcel(@RequestParam("file") MultipartFile file,HttpServletRequest request, HttpServletResponse response) {
try {
// @RequestParam("file") MultipartFile file 是用来接收前端传递过来的文件
// 1.创建workbook对象,读取整个文档
InputStream inputStream = file.getInputStream();
POIFSFileSystem poifsFileSystem = new POIFSFileSystem(inputStream);
HSSFWorkbook wb = new HSSFWorkbook(poifsFileSystem);
// 2.读取页脚sheet
HSSFSheet sheetAt = wb.getSheetAt(0);
// 3.循环读取某一行
for (Row row : sheetAt) {
//先将第二列手机号转换为string格式
row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
// 4.读取每一行的单元格
String stringCellValue="";
String stringCellValue2="";
if(row