Read Excel
1. Read from a file
ExcelReader reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\lingzhifeng\\Desktop\\1.xlsx"));
2. Read from the stream
ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("C:\\Users\\lingzhifeng\\Desktop\\1.xlsx"));
3. Read the specified sheet
//通过sheet编号获取
//reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\lingzhifeng\\Desktop\\1.xlsx"), 0);
//通过sheet名获取
reader = ExcelUtil.getReader(FileUtil.file("C:\\Users\\lingzhifeng\\Desktop\\1.xlsx"), "sheet1");
Display Data
1. Read all rows and columns in Excel and express them as lists
List<List<Object>> read = reader.read();
System.out.println(read);
2. Read as a Map list. By default, the first row is the title row, the key in the Map is the title, and the value is the cell value corresponding to the title.
List<Map<String, Object>> maps = reader.readAll();
System.out.println(maps);
3. Read as a Bean list. The field name in the Bean is the title, and the field value is the cell value corresponding to the title.
ExcelReader reader1 = ExcelUtil.getReader("C:\\Users\\lingzhifeng\\Desktop\\2.xlsx");
List<Person> all = reader1.readAll(Person.class);
System.out.println(all);
![在这里插入图片描述](https://img-blog.csdnimg.cn/acd3cbc90217407ca09d90163e176a3a.png)