whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/util/ExcelUtil.java
@@ -75,11 +75,26 @@
            //不保存缓存信息与response.reset同样效果
            response.addHeader("Pragma", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
            wb.write(os);
            os.flush();
            os.close();
            if(os!=null){
                wb.write(os);
                os.flush();
                os.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //构造指定的单元格样式
    public static HSSFCellStyle createCellStyle(HSSFWorkbook wb,String fontType,int fontSize,boolean center,boolean blod){
        HSSFCellStyle cellStyle = wb.createCellStyle();                                                      //单元格样式
        HSSFFont font = wb.createFont();
        font.setFontName(fontType);
        font.setFontHeightInPoints((short) fontSize);                                                      //设置字体大小
        font.setBoldweight(blod?HSSFFont.BOLDWEIGHT_BOLD:HSSFFont.BOLDWEIGHT_NORMAL);                              //粗体显示
        cellStyle.setFont(font);                                                                        //标题样式
        cellStyle.setAlignment(center?HSSFCellStyle.ALIGN_CENTER_SELECTION:HSSFCellStyle.ALIGN_LEFT);                   // 居中
        return cellStyle;
    }
}