结合相关easyExcel的相关信息
//上传服务器方法,返回url链接地址
public String exportToMinIO(List<aaaDto> list) {
String pathUrl = "";
String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()) + ".xlsx";
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).build();
// ExcelWriter excelWriter = EasyExcel.write(fileName, aaaDto.class).build();
try {
// 这里注意 单独设置sheet的表头
WriteSheet writeSheet = EasyExcel.writerSheet(0,"第一个sheet数据").head(aaaDto.class).build();
excelWriter.write(list, writeSheet);
} catch (Exception e){
log.info("上传文件异常失败:{}", e.getMessage());
} finally {
// 千万别忘记finish 会帮忙关闭流
if (excelWriter != null) {
excelWriter.finish();
MultipartFile file = new MockMultipartFile("SendLocalitiesEmail",
"businessChannels" + ".xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.xlsx", byteArrayOutputStream.toByteArray());
pathUrl = imagesUploadMiNio.uploadExcelFile(fileName,file);
}
}
return pathUrl;
}