1. springboot工程
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.10</version>
</dependency>
2. 实现类
package com.example.demo.controller;
import jxl.Sheet;
import jxl.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
@RestController
public class ImportExcelController {
@RequestMapping(value = "/importExcel")
public void importExcel(@RequestParam("file") MultipartFile multipartFile) {
try {
Workbook workbook = Workbook.getWorkbook(multipartFile.getInputStream());
Sheet sheet = workbook.getSheet(0);
List<List<String>> strList = new ArrayList<>();
int row = sheet.getRows();
for (int i = 1; i < row; i++) {
List<String> list = new ArrayList<>();
String name = sheet.getCell(0,i).getContents().trim();
String age = sheet.getCell(1,i).getContents().trim();
String sex = sheet.getCell(2,i).getContents().trim();
list.add(name);
list.add(age);
list.add(sex);
strList.add(list);
}
System.out.println(strList);
} catch (Exception e) {
e.printStackTrace();
}
}
}
3. 创建一个excel表格(.xls)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ab75036a48d0fc148f27201f2c566f00.png#pic_center)
4. 发起请求
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ac9b0e5ba18b01d387ca7ca52f71544e.png#pic_center)
5. 查看打印
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/419b7286f8f9c342e88e947ac6196bff.png#pic_center)