fei
2025-12-15 5be5c89210dbb626dbb87a81265ff8eef92979df
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
@@ -604,21 +604,35 @@
        style.setFont(dataFont);
        styles.put("data", style);
        // 创建表头样式映射,根据Excel注解动态生成
        Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
        for (Object[] os : fields)
        {
            Excel excel = (Excel) os[1];
            String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
            if (!headerStyles.containsKey(key))
            {
        style = wb.createCellStyle();
        style.cloneStyleFrom(styles.get("data"));
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        // 设置单元格内容自动换行
        style.setWrapText(true);
        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
                // 根据注解设置表头背景色 - 已注释,表头不显示背景色
                /*if (excel.headerBackgroundColor() != IndexedColors.WHITE) {
                    style.setFillForegroundColor(excel.headerBackgroundColor().index);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                }*/
        Font headerFont = wb.createFont();
        headerFont.setFontName("Arial");
        headerFont.setFontHeightInPoints((short) 10);
        headerFont.setBold(true);
        headerFont.setColor(IndexedColors.WHITE.getIndex());
                headerFont.setBold(excel.headerFontBold());
                headerFont.setColor(excel.headerColor().index);
        style.setFont(headerFont);
        styles.put("header", style);
                headerStyles.put(key, style);
            }
        }
        styles.putAll(headerStyles);
        style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
@@ -664,7 +678,9 @@
        // 写入列信息
        cell.setCellValue(attr.name());
        setDataValidation(attr, row, column);
        cell.setCellStyle(styles.get("header"));
        // 根据Excel注解动态选择表头样式
        String key = StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor());
        cell.setCellStyle(styles.get(key));
        return cell;
    }