easyexcel只读取第二行的表头
时间: 2023-07-29 16:13:47 浏览: 397
可以使用EasyExcel的`read`方法,并通过设置`head`参数来只读取第二行作为表头。例如:
```
ExcelReader reader = EasyExcel.read(fileName).build();
List<Object> objects = reader.read(sheetNo, new ReadSheet().setHeadRowNumber(1).setClazz(YourDataClass.class).setHead(YourHeadClass.class)).get(0).getDatas();
```
其中`YourDataClass`是你的数据类,`YourHeadClass`是你的表头类,`setHead(YourHeadClass.class)`表示只读取第二行作为表头。注意,表头类中的属性名称需要与Excel中第二行的表头名称保持一致。
相关问题
easyExcel从第二行开始读取excel
是的,EasyExcel默认从第二行开始读取Excel数据。这是因为在Excel中,第一行通常是表头,而真正的数据通常从第二行开始。如果你需要从其他行开始读取数据,可以使用EasyExcel提供的API来指定读取的起始行。比如,使用`readSheet()`方法的重载版本,可以指定从哪一行开始读取数据。示例代码如下:
```java
EasyExcel.read(fileName)
.sheet(sheetName)
.headRowNumber(0) // 指定表头所在行数
.startRow(2) // 指定从哪一行开始读取数据
.doRead();
```
在上面的代码中,`headRowNumber()`方法用于指定表头所在行数,如果表头在第一行,则可以不用指定。`startRow()`方法用于指定从哪一行开始读取数据,这里指定为第二行。
EasyExcel.read从第几行表头开始读
EasyExcel.read() 方法默认从第一行开始读取,也就是默认第一行是表头。如果你的表头不在第一行,需要指定读取的起始行数,可以使用 `headRowNumber()` 方法来设置表头所在的行数。例如,如果表头在第二行,可以这样使用:
```
EasyExcel.read(fileName).headRowNumber(1).sheet().doRead();
```
其中,`headRowNumber(1)` 表示表头在第二行,因为行数是从0开始计数,所以需要传入1。
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)