🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
```java @RequestMapping("/excel/read") public void read(@RequestParam("file") MultipartFile file) throws IOException { //创建文档 XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream()); //获取表格 XSSFSheet sheet = workbook.getSheetAt(0); //获取总行数 int rows = sheet.getPhysicalNumberOfRows(); for (int i = 0; i < rows; i++) { //获取行 XSSFRow row = sheet.getRow(i); //获取每一行的总列数 int cols = row.getPhysicalNumberOfCells(); for (int k = 0; k < cols; k++) { //获取列 XSSFCell cell = row.getCell(k); //获取值 String value = cell.toString(); System.out.println(value); } } } ```