提供的代码还是有问题 'Sheet' 为 abstract;无法实例化 public static List<Object> readExcelToList(MultipartFile file) throws IOException { List<Object> list = new ArrayList<>(); InputStream inputStream = file.getInputStream(); ExcelReader excelReader = EasyExcel.read(inputStream, new AnalysisEventListener<Object>() { @Override public void invoke(Object data, AnalysisContext context) { list.add(data); } @Override public void doAfterAllAnalysed(AnalysisContext context) { // 解析结束销毁不用的资源 try { context.readWorkbookHolder().getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } }).build(); excelReader.read(new Sheet(1, 1, Object.class)); return list; }
时间: 2024-03-08 08:47:52
浏览: 62
根据提供的[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083),确实存在问题。'Sheet' 是一个抽象类,不能直接实例化。可以改为使用[实体](https://geek.csdn.net/educolumn/032fadf792a9d75ffa33410b908fe2c4?spm=1055.2569.3001.10083)类来代替:
```java
public st[ati](https://geek.csdn.net/educolumn/150d7073277950db5f09620704e791cf?spm=1055.2569.3001.10083)c List<Object> readExcelToList(MultipartFile file) throws IOException {
List<Object> list = new ArrayList<>();
InputStream inputStream = file.[get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083)InputStream();
ExcelReader excelReader = EasyExcel.read(inputStream, new AnalysisEventListener<Object>() {
@Override
public void invoke(Object data, AnalysisContext context) {
list.add(data);
@Override
public void doAfterAl[lan](https://geek.csdn.net/educolumn/2e627c1ce792f2bd6c896ec0221f0ac0?spm=1055.2569.3001.10083)alysed(AnalysisContext context) {
// 解析结束销毁不用的资源
try {
context.readWorkbookHolder().getInputStream().close();
} catch (IOException e) {
```