easyexcel 生成文件流
时间: 2023-12-02 22:43:02 浏览: 166
以下是使用EasyExcel生成文件流的示例代码:
```java
// 导入相关类
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteWorkbook;
// 创建ExcelWriterBuilder对象
ExcelWriterBuilder writerBuilder = EasyExcel.write(outputStream);
// 创建WriteWorkbook对象
WriteWorkbook writeWorkbook = writerBuilder.build();
// 创建ExcelWriterSheetBuilder对象
ExcelWriterSheetBuilder sheetBuilder = writerBuilder.sheet();
// 创建WriteSheet对象
WriteSheet writeSheet = sheetBuilder.build();
// 写入数据
List<List<Object>> data = new ArrayList<>();
data.add(Arrays.asList("姓名", "年龄", "性别"));
data.add(Arrays.asList("张三", 18, "男"));
data.add(Arrays.asList("李四", 20, "女"));
EasyExcel.write(outputStream).sheet().doWrite(data);
// 关闭流
outputStream.close();
```
其中,`outputStream`是一个`OutputStream`对象,可以是文件输出流或网络输出流等。以上代码将会生成一个Excel文件,并将其写入到`outputStream`中。
--相关问题--:
1. EasyExcel支持哪些文件格式?
2. 如何在EasyExcel中读取Excel文件?
阅读全文