EasyExcel.write(out, excelDTO.class)
.registerWriteHandler(new CustemhandlerStyleStrategy())
.registerWriteHandler(excelUtil.getStyleStrategy())
.excelType(ExcelTypeEnum.XLSX)
.sheet("代理人导出")
.doWrite(agentExcelDTOS);
1、write
第一个入参定义生成的文件的代号
第二个入参定义写入数值对象的类型
2、registerWriteHandler用于定义生成excel文件的格式,入参就是格式设置的方法
3、excelType设置导出文件的后缀名,和文件类型
4、sheet设置excel导出文件的sheet名字
5、dowrite需要写入值的对象
设置格式举例在需要设置格式的时候可以如下设置
public class excelUtil extends ExcelUtils {
public static HorizontalCellStyleStrategy getStyleStrategy(){
// 头的策略
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 背景设置为灰色
headWriteCellStyle.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());
WriteFont headWriteFont = new WriteFont();
headWriteFont.setFontHeightInPoints((short)12);
// 字体样式
headWriteFont.setFontName("Frozen");
headWriteCellStyle.setWriteFont(headWriteFont);
//自动换行
headWriteCellStyle.setWrapped(true);
// 水平对齐方式
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 垂直对齐方式
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 内容的策略
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// 背景白色
contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
WriteFont contentWriteFont = new WriteFont();
// 字体大小
contentWriteFont.setFontHeightInPoints((short)12);
// 字体样式
contentWriteFont.setFontName("Calibri");
contentWriteCellStyle.setWriteFont(contentWriteFont);
// 头是头的样式 内容是内容的样式 其他的策略可以自己实现
return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
}
}
上传文件至OSS,并获取下载链接
@Autowired protected StoreTool ossTool; String ossKey = "bops/" +"xxxxxx" + "/" + fileName; ossTool.PRIVATE().uploadFile(new ByteArrayInputStream(out.toByteArray()), ossKey); fileUrl = ossTool.PRIVATE().generatorOssUrl(ossKey);
1、设置ossKey
2、ossTool.PRIVATE().uploadFile()入参中,out就是上传文件的代号,后面是设置的osskey关键字
3、通过ossTool.PRIVATE().generatorOssUrl方法获取到文件地址



