easyexcel写入ByteArrayOutputStream
easyexcel
快速、简洁、解决大文件内存溢出的java处理Excel工具
项目地址:https://gitcode.com/gh_mirrors/ea/easyexcel
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
定义ExcelViewObject
public class ExcelViewObject {
@ColumnWidth(12)
@ExcelProperty(value = "首列")
private String type;
@ColumnWidth(12)
@ExcelProperty(value = "第二列")
private String name;
插入数据,输出到ByteArrayOutputStream;ByteArrayOutputStream作为常用的字节流,输出后可以作为接口数据来传送;
ByteArrayOutputStream out = new ByteArrayOutputStream();
List<ExcelViewObject> data = new ArrayList<>();
将要插入的数据遍历插入,如果不需转换直接addAll();
for (POObject item : list) {
ExcelViewObject excelViewObject = new ExcelViewObject();
BeanUtils.copyProperties(item, excelViewObject);
data.add(ExcelViewObject);
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(out, ExcelViewObject.class)
.registerWriteHandler(horizontalCellStyleStrategy).sheet().doWrite(data);
# java
GitHub 加速计划 / ea / easyexcel
31.63 K
7.46 K
快速、简洁、解决大文件内存溢出的java处理Excel工具
最近提交
(Master分支:30 天前 )
c42183df
Bugfix
28 天前
efa7dff6
* 重新加回 `commons-io`
28 天前
所有评论(0)