官网:https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java各种设置【使用easyexcel导出excel--字体居中】_ekkcole的博客-CSDN博客_easy excel 文字居中
直接使用的工具类,可以设置内容居中,字体大小,字体,颜色等,可以去官网研究
/**
* @author :si
* @date :2022/11/23
*/
public class EasyExeclUtils {
public static HorizontalCellStyleStrategy setDownLoadExcel(HttpServletResponse response){
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//内容策略
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置 水平居中
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
WriteFont headWriteFont = new WriteFont();
headWriteFont.setFontHeightInPoints((short)13);
headWriteCellStyle.setWriteFont(headWriteFont);
headWriteFont.setColor(IndexedColors.RED.getIndex());
WriteFont contentWriteFont = new WriteFont();
// 字体大小
contentWriteFont.setFontHeightInPoints((short)11);
contentWriteFont.setFontName("宋体");
contentWriteCellStyle.setWriteFont(contentWriteFont);
headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return horizontalCellStyleStrategy;
}
}