导出结果样excel例
使用到的注解
@Excel(name = "日期", needMerge = true,format = "yyyy-MM-dd")
@Excel(name = "班次", needMerge = true, replace = {"白班_day", "夜班_night"})
@ExcelCollection(name = "图片上传")
@Excel(name = "图片上传", type = 2, width = 60, height = 60, imageType = 2)
// type=2该字段类型为图片;imageType=2表示从数据库中读取;width = 60, height = 60表示占单元格大小。
实体类
public class Record
@Excel(name = "日期", needMerge = true,format = "yyyy-MM-dd")
@JSONField(format = "yyyy-MM-dd")
private Date operationDate;
@Excel(name = "班次", needMerge = true, replace = {"白班_day", "夜班_night"})
private String operatorShift;
@TableField(typeHandler = FastjsonTypeHandler.class)
private List<String> attachment;// 存放图片链接 保存到数据库
@TableField(exist = false)
@ExcelCollection(name = "图片上传")
private List<DD> imgFile;// 用于导出图片
@Data
public static class DD {
@Excel(name = "图片上传", type = 2, width = 60, height = 60, imageType = 2)
private byte[] bytes;
}
}
图片本质上是byte[],如果private List<DD> imgFile改写为private List<byte[]> imgFile,导出时不会成功(只是大体debug了下,还没仔细看)。我的解决方法就是将byte[]封装到对象中然后导出。
处理图片的代码之后有时间贴一下,百度一下也可以搜索到