feixian_weifajianguan/Infrastructure/Utilities/Excel/ExcelHeaderStyleAttribute.cs

47 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
}