EasyExcel 实现多个Sheet页导出
时间: 2024-05-10 15:16:56 浏览: 290
在 EasyExcel 中,可以通过 `Sheet` 类来创建多个 Sheet 页,并将数据写入到各个 Sheet 中,最后再将这些 Sheet 导出为一个 Excel 文件。以下是一个示例代码:
```java
// 创建 Excel 对象
ExcelWriter writer = EasyExcel.write("example.xlsx").build();
// 创建第一个 Sheet
Sheet sheet1 = new Sheet(1, 0);
sheet1.setSheetName("Sheet 1");
List<List<String>> data1 = new ArrayList<>();
// 写入数据到第一个 Sheet
// ...
// 创建第二个 Sheet
Sheet sheet2 = new Sheet(2, 0);
sheet2.setSheetName("Sheet 2");
List<List<String>> data2 = new ArrayList<>();
// 写入数据到第二个 Sheet
// ...
// 将两个 Sheet 添加到 Excel 中
writer.write(data1, sheet1);
writer.write(data2, sheet2);
// 关闭 Excel 对象
writer.finish();
```
在上述代码中,首先创建了一个 `ExcelWriter` 对象,然后通过 `Sheet` 类分别创建了两个 Sheet 页,并将数据写入到各自的 Sheet 中,最后将这两个 Sheet 页添加到 Excel 对象中,并关闭 Excel 对象以完成导出。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![xlsx](https://img-home.csdnimg.cn/images/20241231045042.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)