本文来告诉大家 ECMA 376 文档的 20.1.10.47 章的 ST_PresetColorVal 预设颜色值对应的颜色
在 OpenXML SDK 里面,根据传入的 DocumentFormat.OpenXml.Drawing.PresetColorValues 可以获取到 ST_PresetColorVal 预设颜色值,而这些颜色值在 ECMA 376 文档的 20.1.10.47 章,定义的颜色是 RGB 格式的颜色
/// <summary>
/// 处理预设颜色值 请参阅 ECMA 376 的 20.1.10.47 ST_PresetColorVal (Preset Color Value) 文档
/// </summary>
internal static class PresetColorMap
{
internal static Color BuildPreSetColor(PresetColorValues value)
{
return value switch
{
PresetColorValues.AliceBlue => new Color { A = 0xFF, R = 240, G = 248, B = 255 },
PresetColorValues.AntiqueWhite => new Color { A = 0xFF, R = 250, G = 235, B = 215 },
PresetColorValues.Aqua => new Color { A = 0xFF, R = 0, G = 255, B = 255 },
PresetColorValues.Aquamarine => new Color { A = 0xFF, R = 127, G = 255, B = 212 },
PresetColorValues.Azure => new Color { A = 0xFF, R = 240, G = 255, B = 255 },
PresetColorValues.Beige => new Color { A = 0xFF, R = 245, G = 245, B = 220 },
PresetColorValues.Bisque => new Color { A = 0xFF, R = 255, G = 228, B = 196 },
PresetColorValues.Black => new Color { A = 0xFF, R = 0, G = 0, B = 0 },
PresetColorValues.BlanchedAlmond => new Color { A = 0xFF, R = 255, G = 235, B = 205 },
PresetColorValues.Blue => new Color { A = 0xFF, R = 0, G = 0, B = 255 },
PresetColorValues.BlueViolet => new Color { A = 0xFF, R = 138, G = 43, B = 226 },
PresetColorValues.Brown => new Color { A = 0xFF, R = 165, G = 42, B = 42 },
PresetColorValues.BurlyWood => new Color { A = 0xFF, R = 222, G = 184, B = 135 },
PresetColorValues.CadetBlue => new Color { A = 0xFF, R = 95, G = 158, B = 160 },
PresetColorValues.Chartreuse => new Color { A = 0xFF, R = 127, G = 255, B = 0 },
PresetColorValues.Chocolate => new Color { A = 0xFF, R = 210, G = 105, B = 30 },
PresetColorValues.Coral => new Color { A = 0xFF, R = 255, G = 127, B = 80 },
PresetColorValues.CornflowerBlue => new Color { A = 0xFF, R = 100, G = 149, B = 237 },
PresetColorValues.Cornsilk => new Color { A = 0xFF, R = 255, G = 248, B = 220 },
PresetColorValues.Crimson => new Color { A = 0xFF, R = 220, G = 20, B = 60 },
PresetColorValues.Cyan => new Color { A = 0xFF, R = 0, G = 255, B = 255 },
PresetColorValues.DarkBlue2010 => new Color { A = 0xFF, R = 0, G = 0, B = 139 },
PresetColorValues.DarkCyan2010 => new Color { A = 0xFF, R = 0, G = 139, B = 139 },
PresetColorValues.DarkGoldenrod2010 => new Color { A = 0xFF, R = 184, G = 134, B = 11 },
PresetColorValues.DarkGray2010 => new Color { A = 0xFF, R = 169, G = 169, B = 169 },
PresetColorValues.DarkGrey2010 => new Color { A = 0xFF, R = 169, G = 169, B = 169 },
PresetColorValues.DarkGreen2010 => new Color { A = 0xFF, R = 0, G = 100, B = 0 },
PresetColorValues.DarkKhaki2010 => new Color { A = 0xFF, R = 189, G = 183, B = 107 },
PresetColorValues.DarkMagenta2010 => new Color { A = 0xFF, R = 139, G = 0, B = 139 },
PresetColorValues.DarkOliveGreen2010 => new Color { A = 0xFF, R = 85, G = 107, B = 47 },
PresetColorValues.DarkOrange2010 => new Color { A = 0xFF, R = 255, G = 140, B = 0 },
PresetColorValues.DarkOrchid2010 => new Color { A = 0xFF, R = 153, G = 50, B = 204 },
PresetColorValues.DarkRed2010 => new Color { A = 0xFF, R = 139, G = 0, B = 0 },
PresetColorValues.DarkSalmon2010 => new Color { A = 0xFF, R = 233, G = 150, B = 122 },
PresetColorValues.DarkSeaGreen2010 => new Color { A = 0xFF, R = 143, G = 188, B = 139 },
PresetColorValues.DarkSlateBlue2010 => new Color { A = 0xFF, R = 72, G = 61, B = 139 },
PresetColorValues.DarkSlateGray2010 => new Color { A = 0xFF, R = 47, G = 79, B = 79 },
PresetColorValues.DarkSlateGrey2010 => new Color { A = 0xFF, R = 47, G = 79, B = 79 },
PresetColorValues.DarkTurquoise2010 => new Color { A = 0xFF, R = 0, G = 206, B = 209 },
PresetColorValues.DarkViolet2010 => new Color { A = 0xFF, R = 148, G = 0, B = 211 },
PresetColorValues.DarkBlue => new Color { A = 0xFF, R = 0, G = 0, B = 139 },
PresetColorValues.DarkCyan => new Color { A = 0xFF, R = 0, G = 139, B = 139 },
PresetColorValues.DarkGoldenrod => new Color { A = 0xFF, R = 184, G = 134, B = 11 },
PresetColorValues.DarkGray => new Color { A = 0xFF, R = 169, G = 169, B = 169 },
PresetColorValues.DarkGrey => new Color { A = 0xFF, R = 169, G = 169, B = 169 },
PresetColorValues.DarkGreen => new Color { A = 0xFF, R = 0, G = 100, B = 0 },
PresetColorValues.DarkKhaki => new Color { A = 0xFF, R = 189, G = 183, B = 107 },
PresetColorValues.DarkMagenta => new Color { A = 0xFF, R = 139, G = 0, B = 139 },
PresetColorValues.DarkOliveGreen => new Color { A = 0xFF, R = 85, G = 107, B = 47 },
PresetColorValues.DarkOrange => new Color { A = 0xFF, R = 255, G = 140, B = 0 },
PresetColorValues.DarkOrchid => new Color { A = 0xFF, R = 153, G = 50, B = 204 },
PresetColorValues.DarkRed => new Color { A = 0xFF, R = 139, G = 0, B = 0 },
PresetColorValues.DarkSalmon => new Color { A = 0xFF, R = 233, G = 150, B = 122 },
PresetColorValues.DarkSeaGreen => new Color { A = 0xFF, R = 143, G = 188, B = 139 },
PresetColorValues.DarkSlateBlue => new Color { A = 0xFF, R = 72, G = 61, B = 139 },
PresetColorValues.DarkSlateGray => new Color { A = 0xFF, R = 47, G = 79, B = 79 },
PresetColorValues.DarkSlateGrey => new Color { A = 0xFF, R = 47, G = 79, B = 79 },
PresetColorValues.DarkTurquoise => new Color { A = 0xFF, R = 0, G = 206, B = 209 },
PresetColorValues.DarkViolet => new Color { A = 0xFF, R = 148, G = 0, B = 211 },
PresetColorValues.DeepPink => new Color { A = 0xFF, R = 255, G = 20, B = 147 },
PresetColorValues.DeepSkyBlue => new Color { A = 0xFF, R = 0, G = 191, B = 255 },
PresetColorValues.DimGray => new Color { A = 0xFF, R = 105, G = 105, B = 105 },
PresetColorValues.DimGrey => new Color { A = 0xFF, R = 0, G = 0, B = 139 },
PresetColorValues.DodgerBlue => new Color { A = 0xFF, R = 30, G = 144, B = 255 },
PresetColorValues.Firebrick => new Color { A = 0xFF, R = 178, G = 34, B = 34 },
PresetColorValues.FloralWhite => new Color { A = 0xFF, R = 255, G = 250, B = 240 },
PresetColorValues.ForestGreen => new Color { A = 0xFF, R = 34, G = 139, B = 34 },
PresetColorValues.Fuchsia => new Color { A = 0xFF, R = 255, G = 0, B = 255 },
PresetColorValues.Gainsboro => new Color { A = 0xFF, R = 220, G = 220, B = 220 },
PresetColorValues.GhostWhite => new Color { A = 0xFF, R = 248, G = 248, B = 255 },
PresetColorValues.Gold => new Color { A = 0xFF, R = 255, G = 215, B = 0 },
PresetColorValues.Goldenrod => new Color { A = 0xFF, R = 218, G = 165, B = 32 },
PresetColorValues.Gray => new Color { A = 0xFF, R = 128, G = 128, B = 128 },
PresetColorValues.Grey => new Color { A = 0xFF, R = 128, G = 128, B = 128 },
PresetColorValues.Green => new Color { A = 0xFF, R = 0, G = 128, B = 0 },
PresetColorValues.GreenYellow => new Color { A = 0xFF, R = 173, G = 255, B = 47 },
PresetColorValues.Honeydew => new Color { A = 0xFF, R = 240, G = 255, B = 240 },
PresetColorValues.HotPink => new Color { A = 0xFF, R = 255, G = 105, B = 180 },
PresetColorValues.IndianRed => new Color { A = 0xFF, R = 205, G = 92, B = 92 },
PresetColorValues.Indigo => new Color { A = 0xFF, R = 75, G = 0, B = 130 },
PresetColorValues.Ivory => new Color { A = 0xFF, R = 255, G = 255, B = 240 },
PresetColorValues.Khaki => new Color { A = 0xFF, R = 240, G = 230, B = 140 },
PresetColorValues.Lavender => new Color { A = 0xFF, R = 230, G = 230, B = 250 },
PresetColorValues.LavenderBlush => new Color { A = 0xFF, R = 255, G = 240, B = 245 },
PresetColorValues.LawnGreen => new Color { A = 0xFF, R = 124, G = 252, B = 0 },
PresetColorValues.LemonChiffon => new Color { A = 0xFF, R = 255, G = 250, B = 205 },
PresetColorValues.LightBlue2010 => new Color { A = 0xFF, R = 173, G = 216, B = 230 },
PresetColorValues.LightCoral2010 => new Color { A = 0xFF, R = 240, G = 128, B = 128 },
PresetColorValues.LightCyan2010 => new Color { A = 0xFF, R = 224, G = 255, B = 255 },
PresetColorValues.LightGoldenrodYellow2010 => new Color { A = 0xFF, R = 250, G = 250, B = 120 },
PresetColorValues.LightGray2010 => new Color { A = 0xFF, R = 211, G = 211, B = 211 },
PresetColorValues.LightGrey2010 => new Color { A = 0xFF, R = 211, G = 211, B = 211 },
PresetColorValues.LightGreen2010 => new Color { A = 0xFF, R = 144, G = 238, B = 144 },
PresetColorValues.LightPink2010 => new Color { A = 0xFF, R = 255, G = 182, B = 193 },
PresetColorValues.LightSalmon2010 => new Color { A = 0xFF, R = 255, G = 160, B = 122 },
PresetColorValues.LightSeaGreen2010 => new Color { A = 0xFF, R = 32, G = 178, B = 170 },
PresetColorValues.LightSkyBlue2010 => new Color { A = 0xFF, R = 135, G = 206, B = 250 },
PresetColorValues.LightSlateGray2010 => new Color { A = 0xFF, R = 119, G = 136, B = 153 },
PresetColorValues.LightSlateGrey2010 => new Color { A = 0xFF, R = 119, G = 136, B = 153 },
PresetColorValues.LightSteelBlue2010 => new Color { A = 0xFF, R = 176, G = 196, B = 222 },
PresetColorValues.LightYellow2010 => new Color { A = 0xFF, R = 255, G = 255, B = 224 },
PresetColorValues.LightBlue => new Color { A = 0xFF, R = 173, G = 216, B = 230 },
PresetColorValues.LightCoral => new Color { A = 0xFF, R = 240, G = 128, B = 128 },
PresetColorValues.LightCyan => new Color { A = 0xFF, R = 224, G = 255, B = 255 },
PresetColorValues.LightGoldenrodYellow => new Color { A = 0xFF, R = 250, G = 250, B = 120 },
PresetColorValues.LightGray => new Color { A = 0xFF, R = 211, G = 211, B = 211 },
PresetColorValues.LightGrey => new Color { A = 0xFF, R = 211, G = 211, B = 211 },
PresetColorValues.LightGreen => new Color { A = 0xFF, R = 144, G = 238, B = 144 },
PresetColorValues.LightPink => new Color { A = 0xFF, R = 255, G = 182, B = 193 },
PresetColorValues.LightSalmon => new Color { A = 0xFF, R = 255, G = 160, B = 122 },
PresetColorValues.LightSeaGreen => new Color { A = 0xFF, R = 32, G = 178, B = 170 },
PresetColorValues.LightSkyBlue => new Color { A = 0xFF, R = 135, G = 206, B = 250 },
PresetColorValues.LightSlateGray => new Color { A = 0xFF, R = 119, G = 136, B = 153 },
PresetColorValues.LightSlateGrey => new Color { A = 0xFF, R = 119, G = 136, B = 153 },
PresetColorValues.LightSteelBlue => new Color { A = 0xFF, R = 176, G = 196, B = 222 },
PresetColorValues.LightYellow => new Color { A = 0xFF, R = 255, G = 255, B = 224 },
PresetColorValues.Lime => new Color { A = 0xFF, R = 0, G = 255, B = 0 },
PresetColorValues.LimeGreen => new Color { A = 0xFF, R = 50, G = 205, B = 50 },
PresetColorValues.Linen => new Color { A = 0xFF, R = 250, G = 240, B = 230 },
PresetColorValues.Magenta => new Color { A = 0xFF, R = 255, G = 0, B = 255 },
PresetColorValues.Maroon => new Color { A = 0xFF, R = 128, G = 0, B = 0 },
PresetColorValues.MedAquamarine => new Color { A = 0xFF, R = 102, G = 205, B = 170 },
PresetColorValues.MediumBlue => new Color { A = 0xFF, R = 0, G = 0, B = 205 },
PresetColorValues.MediumOrchid => new Color { A = 0xFF, R = 186, G = 85, B = 211 },
PresetColorValues.MediumPurple => new Color { A = 0xFF, R = 147, G = 112, B = 219 },
PresetColorValues.MediumSeaGreen => new Color { A = 0xFF, R = 60, G = 179, B = 113 },
PresetColorValues.MediumSlateBlue => new Color { A = 0xFF, R = 123, G = 104, B = 238 },
PresetColorValues.MediumSpringGreen => new Color { A = 0xFF, R = 0, G = 250, B = 154 },
PresetColorValues.MediumTurquoise => new Color { A = 0xFF, R = 72, G = 209, B = 204 },
PresetColorValues.MediumVioletRed => new Color { A = 0xFF, R = 199, G = 21, B = 133 },
PresetColorValues.MediumAquamarine2010 => new Color { A = 0xFF, R = 102, G = 205, B = 170 },
PresetColorValues.MediumBlue2010 => new Color { A = 0xFF, R = 0, G = 0, B = 205 },
PresetColorValues.MediumOrchid2010 => new Color { A = 0xFF, R = 186, G = 85, B = 211 },
PresetColorValues.MediumPurple2010 => new Color { A = 0xFF, R = 147, G = 112, B = 219 },
PresetColorValues.MediumSeaGreen2010 => new Color { A = 0xFF, R = 60, G = 179, B = 113 },
PresetColorValues.MediumSlateBlue2010 => new Color { A = 0xFF, R = 123, G = 104, B = 238 },
PresetColorValues.MediumSpringGreen2010 => new Color { A = 0xFF, R = 0, G = 250, B = 154 },
PresetColorValues.MediumTurquoise2010 => new Color { A = 0xFF, R = 72, G = 209, B = 204 },
PresetColorValues.MediumVioletRed2010 => new Color { A = 0xFF, R = 199, G = 21, B = 133 },
PresetColorValues.MidnightBlue => new Color { A = 0xFF, R = 25, G = 25, B = 112 },
PresetColorValues.MintCream => new Color { A = 0xFF, R = 245, G = 255, B = 250 },
PresetColorValues.MistyRose => new Color { A = 0xFF, R = 255, G = 228, B = 225 },
PresetColorValues.Moccasin => new Color { A = 0xFF, R = 255, G = 228, B = 181 },
PresetColorValues.NavajoWhite => new Color { A = 0xFF, R = 255, G = 222, B = 173 },
PresetColorValues.Navy => new Color { A = 0xFF, R = 0, G = 0, B = 128 },
PresetColorValues.OldLace => new Color { A = 0xFF, R = 253, G = 245, B = 230 },
PresetColorValues.Olive => new Color { A = 0xFF, R = 128, G = 128, B = 0 },
PresetColorValues.OliveDrab => new Color { A = 0xFF, R = 107, G = 142, B = 35 },
PresetColorValues.Orange => new Color { A = 0xFF, R = 255, G = 165, B = 0 },
PresetColorValues.OrangeRed => new Color { A = 0xFF, R = 255, G = 69, B = 0 },
PresetColorValues.Orchid => new Color { A = 0xFF, R = 218, G = 112, B = 214 },
PresetColorValues.PaleGoldenrod => new Color { A = 0xFF, R = 238, G = 232, B = 170 },
PresetColorValues.PaleGreen => new Color { A = 0xFF, R = 152, G = 251, B = 152 },
PresetColorValues.PaleTurquoise => new Color { A = 0xFF, R = 175, G = 238, B = 238 },
PresetColorValues.PaleVioletRed => new Color { A = 0xFF, R = 219, G = 112, B = 147 },
PresetColorValues.PapayaWhip => new Color { A = 0xFF, R = 255, G = 239, B = 213 },
PresetColorValues.PeachPuff => new Color { A = 0xFF, R = 255, G = 218, B = 185 },
PresetColorValues.Peru => new Color { A = 0xFF, R = 205, G = 133, B = 63 },
PresetColorValues.Pink => new Color { A = 0xFF, R = 255, G = 192, B = 203 },
PresetColorValues.Plum => new Color { A = 0xFF, R = 221, G = 160, B = 221 },
PresetColorValues.PowderBlue => new Color { A = 0xFF, R = 176, G = 224, B = 230 },
PresetColorValues.Purple => new Color { A = 0xFF, R = 128, G = 0, B = 128 },
PresetColorValues.Red => new Color { A = 0xFF, R = 255, G = 0, B = 0 },
PresetColorValues.RosyBrown => new Color { A = 0xFF, R = 188, G = 143, B = 143 },
PresetColorValues.RoyalBlue => new Color { A = 0xFF, R = 65, G = 105, B = 225 },
PresetColorValues.SaddleBrown => new Color { A = 0xFF, R = 139, G = 69, B = 19 },
PresetColorValues.Salmon => new Color { A = 0xFF, R = 250, G = 128, B = 114 },
PresetColorValues.SandyBrown => new Color { A = 0xFF, R = 244, G = 164, B = 96 },
PresetColorValues.SeaGreen => new Color { A = 0xFF, R = 46, G = 139, B = 87 },
PresetColorValues.SeaShell => new Color { A = 0xFF, R = 255, G = 245, B = 238 },
PresetColorValues.Sienna => new Color { A = 0xFF, R = 160, G = 82, B = 45 },
PresetColorValues.Silver => new Color { A = 0xFF, R = 192, G = 192, B = 19 },
PresetColorValues.SkyBlue => new Color { A = 0xFF, R = 135, G = 206, B = 235 },
PresetColorValues.SlateBlue => new Color { A = 0xFF, R = 135, G = 206, B = 235 },
PresetColorValues.SlateGray => new Color { A = 0xFF, R = 112, G = 128, B = 144 },
PresetColorValues.SlateGrey => new Color { A = 0xFF, R = 112, G = 128, B = 144 },
PresetColorValues.Snow => new Color { A = 0xFF, R = 255, G = 250, B = 250 },
PresetColorValues.SpringGreen => new Color { A = 0xFF, R = 0, G = 255, B = 127 },
PresetColorValues.SteelBlue => new Color { A = 0xFF, R = 70, G = 130, B = 180 },
PresetColorValues.Tan => new Color { A = 0xFF, R = 210, G = 180, B = 140 },
PresetColorValues.Teal => new Color { A = 0xFF, R = 0, G = 128, B = 128 },
PresetColorValues.Thistle => new Color { A = 0xFF, R = 216, G = 191, B = 21 },
PresetColorValues.Tomato => new Color { A = 0xFF, R = 255, G = 99, B = 71 },
PresetColorValues.Turquoise => new Color { A = 0xFF, R = 64, G = 224, B = 208 },
PresetColorValues.Violet => new Color { A = 0xFF, R = 238, G = 130, B = 238 },
PresetColorValues.Wheat => new Color { A = 0xFF, R = 245, G = 222, B = 179 },
PresetColorValues.White => new Color { A = 0xFF, R = 255, G = 255, B = 255 },
PresetColorValues.WhiteSmoke => new Color { A = 0xFF, R = 245, G = 245, B = 245 },
PresetColorValues.Yellow => new Color { A = 0xFF, R = 255, G = 255, B = 0 },
PresetColorValues.YellowGreen => new Color { A = 0xFF, R = 154, G = 205, B = 50 },
_ => null!
};
}
}
以上的 Color 类型是我随意定义的类型,里面有 A R G B 属性
本文会经常更新,请阅读原文: https://blog.lindexi.com/post/dotnet-OpenXML-%E9%A2%84%E8%AE%BE-PresetColorValues-%E9%A2%9C%E8%89%B2%E5%AF%B9%E5%BA%94%E7%9A%84%E5%80%BC.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。
如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者收藏我的博客导航
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 。
无盈利,不卖课,做纯粹的技术博客
以下是广告时间
推荐关注 Edi.Wang 的公众号
欢迎进入 Eleven 老师组建的 .NET 社区
以上广告全是友情推广,无盈利