修改指定sheet和行列的数据
时间: 2024-03-02 20:54:27 浏览: 25
可以使用EasyExcel提供的API来修改指定sheet和行列的数据。首先,使用`EasyExcel.read()`方法读取源文件中指定的sheet,然后使用`Sheet`对象的API来修改指定行列的数据,最后使用`EasyExcel.write()`方法将修改后的数据写回原文件。
下面是一个示例代码:
```java
// 读取指定sheet
ExcelReader excelReader = EasyExcel.read("source.xlsx").build();
Sheet sheet = excelReader.readSheet("Sheet1");
// 修改指定行列的数据
sheet.getRow(0).getCell(0).setCellValue("new value");
// 将修改后的数据写回原文件
EasyExcel.write("source.xlsx").withTemplate("source.xlsx").sheet("Sheet1").doWrite(sheet);
```
在这个示例中,我们使用`EasyExcel.read()`方法读取名为"source.xlsx"的源文件,并使用`readSheet()`方法读取指定的sheet。然后,使用`Sheet`对象的`getRow()`和`getCell()`方法来获取指定行列的单元格,并使用`setCellValue()`方法修改单元格的值。最后,使用`EasyExcel.write()`方法将修改后的数据写回原文件。需要注意的是,`withTemplate()`方法的参数要与`write()`方法的参数一致,才能成功写回原文件。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](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)