using Color = System.Drawing.Color; namespace Infrastructure.Utilities.Excel; // 用于Color类型 // 自定义特性类,用于存储表头样式信息 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, Inherited = false)] public class ExcelHeaderStyleAttribute : Attribute { public string FontName { get; set; } public float FontSize { get; set; } public string FontColor { get; set; } public bool Bold { get; set; } public bool Italic { get; set; } public HorizontalAlignment HorizontalAlignment { get; set; } // 注意:这里的HorizontalAlignment需要自定义或引用相关枚举 // 构造函数,用于初始化特性 public ExcelHeaderStyleAttribute(string fontName, float fontSize, string fontColor, bool bold, bool italic, HorizontalAlignment horizontalAlignment) { FontName = fontName; FontSize = fontSize; FontColor = fontColor; Bold = bold; Italic = italic; HorizontalAlignment = horizontalAlignment; } // 为了方便,可以提供一个简化的构造函数 public ExcelHeaderStyleAttribute() : this("Microsoft YaHei", 12f, "black", false, false, HorizontalAlignment.General) { } } // 自定义的HorizontalAlignment枚举(如果未从其他库引用) public enum HorizontalAlignment { General, Left, Center, Right, Fill, Justify, CenterContinuous, Distributed }