NanoXLSX.Core 3.0.0-rc.5
Loading...
Searching...
No Matches
IndexedColor.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2026
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
10using NanoXLSX.Utils;
11using static NanoXLSX.Colors.IndexedColor;
12
13namespace NanoXLSX.Colors
14{
18 public class IndexedColor : ITypedColor<Value>
19 {
172
176 public const Value DefaultIndexedColor = Value.SystemForeground;
180 public const string DefaultSystemForegroundColorArgb = "FF000000";
184 public const string DefaultSystemBackgroundColorArgb = "FFFFFFFF";
185
186
190 public Value ColorValue { get; set; }
191
196
201 {
203 }
204
209 public IndexedColor(Value color)
210 {
211 ColorValue = color;
212 }
213
219 public IndexedColor(int colorIndex)
220 {
221 if (colorIndex < 0 || colorIndex > 65)
222 {
223 throw new StyleException("Indexed color value must be between 0 and 65.");
224 }
225 ColorValue = (Value)colorIndex;
226 }
227
232 public string GetArgbValue()
233 {
234 return GetArgbValue(ColorValue);
235 }
236
242 {
243 return new SrgbColor(GetArgbValue());
244 }
245
246
252 public override bool Equals(object obj)
253 {
254 return obj is IndexedColor color &&
255 ColorValue == color.ColorValue;
256 }
257
262 public override int GetHashCode()
263 {
264 return 800285905 + ColorValue.GetHashCode();
265 }
266
272 public static string GetArgbValue(Value indexedValue)
273 {
274 switch (indexedValue)
275 {
276 // 0–7 (duplicates of 8–15)
277 case Value.Black0:
278 case Value.Black:
279 return "FF000000";
280
281 case Value.White1:
282 case Value.White:
283 return "FFFFFFFF";
284
285 case Value.Red2:
286 case Value.Red:
287 return "FFFF0000";
288
289 case Value.BrightGreen3:
290 case Value.BrightGreen:
291 return "FF00FF00";
292
293 case Value.Blue4:
294 case Value.Blue:
295 case Value.PureBlue:
296 return "FF0000FF";
297
298 case Value.Yellow5:
299 case Value.Yellow:
300 case Value.StrongYellow:
301 return "FFFFFF00";
302
303 case Value.Magenta6:
304 case Value.Magenta:
305 case Value.StrongMagenta:
306 return "FFFF00FF";
307
308 case Value.Cyan7:
309 case Value.Cyan:
310 case Value.StrongCyan:
311 return "FF00FFFF";
312
313 // Extended palette
314 case Value.DarkRed:
315 case Value.DarkMaroon:
316 return "FF800000";
317
318 case Value.DarkGreen:
319 return "FF008000";
320
321 case Value.DarkBlue:
322 case Value.Navy:
323 return "FF000080";
324
325 case Value.Olive:
326 return "FF808000";
327
328 case Value.Purple:
329 case Value.DarkViolet:
330 return "FF800080";
331
332 case Value.Teal:
333 case Value.DarkTeal:
334 return "FF008080";
335
336 case Value.LightGray:
337 return "FFC0C0C0";
338
339 case Value.Gray:
340 return "FF808080";
341
342 case Value.LightCornflowerBlue:
343 return "FF9999FF";
344
345 case Value.DarkRose:
346 case Value.DarkRoseDuplicate:
347 return "FF993366";
348
349 case Value.LightYellow:
350 return "FFFFFFCC";
351
352 case Value.LightCyan:
353 case Value.PaleCyan:
354 return "FFCCFFFF";
355
356 case Value.DarkPurple:
357 return "FF660066";
358
359 case Value.Salmon:
360 return "FFFF8080";
361
362 case Value.MediumBlue:
363 return "FF0066CC";
364
365 case Value.LightLavender:
366 return "FFCCCCFF";
367
368 case Value.SkyBlue:
369 return "FF00CCFF";
370
371 case Value.LightMint:
372 return "FFCCFFCC";
373
374 case Value.PastelYellow:
375 return "FFFFFF99";
376
377 case Value.LightSkyBlue:
378 return "FF99CCFF";
379
380 case Value.Rose:
381 return "FFFF99CC";
382
383 case Value.Lavender:
384 return "FFCC99FF";
385
386 case Value.Peach:
387 return "FFFFCC99";
388
389 case Value.RoyalBlue:
390 return "FF3366FF";
391
392 case Value.Turquoise:
393 return "FF33CCCC";
394
395 case Value.LightOlive:
396 return "FF99CC00";
397
398 case Value.Gold:
399 return "FFFFCC00";
400
401 case Value.Orange:
402 return "FFFF9900";
403
404 case Value.DarkOrange:
405 return "FFFF6600";
406
407 case Value.BlueGray:
408 return "FF666699";
409
410 case Value.MediumGray:
411 return "FF969696";
412
413 case Value.DarkSlateBlue:
414 return "FF003366";
415
416 case Value.SeaGreen:
417 return "FF339966";
418
419 case Value.VeryDarkGreen:
420 return "FF003300";
421
422 case Value.DarkOlive:
423 return "FF333300";
424
425 case Value.Brown:
426 return "FF993300";
427
428 case Value.Indigo:
429 return "FF333399";
430
431 case Value.VeryDarkGray:
432 return "FF333333";
433
434 case Value.SystemBackground:
435 // Excel default: white background
437
438 default:
439 // Excel default: black text
441 }
442 }
443
448 public static implicit operator IndexedColor(Value value)
449 {
450 return new IndexedColor(value);
451 }
452 }
453}
Class representing an indexed color from the legacy OOXML / Excel indexed color palette.
IndexedColor()
Default constructor with default indexed color.
Value ColorValue
Value of the indexed color.
IndexedColor(Value color)
Constructor with specified indexed color value.
string GetArgbValue()
Gets the ARGB hex code representation of the indexed color.
string StringValue
String representation of the indexed color value.
const string DefaultSystemBackgroundColorArgb
Default ARGB value for system background color.
static string GetArgbValue(Value indexedValue)
Maps the indexed color value to its ARGB hex code representation.
override int GetHashCode()
Gets the hash code of the instance.
Value
Legacy OOXML / Excel indexed color palette.
@ Magenta6
Magenta (duplicate of index 14).
@ DarkOrange
Dark orange (FF6600).
@ Cyan
Cyan / Aqua (#00FFFF).
@ DarkSlateBlue
Dark slate blue (#003366).
@ Yellow5
Yellow (duplicate of index 13).
@ Cyan7
Cyan (duplicate of index 15).
@ Navy
Dark navy blue (#000080).
@ MediumGray
Medium gray (#969696).
@ White1
White (duplicate of index 9).
@ Blue4
Blue (duplicate of index 12).
@ VeryDarkGray
Very dark gray (#333333).
@ Black0
Black (duplicate of index 8).
@ RoyalBlue
Royal blue (#3366FF).
@ DarkRoseDuplicate
Dark rose (duplicate of index 25).
@ PastelYellow
Light pastel yellow (FFFF99).
@ SystemBackground
System background color.
@ SystemForeground
System foreground color.
@ LightLavender
Light lavender blue (CCCCFF).
@ LightOlive
Light olive green (#99CC00).
@ StrongCyan
Strong cyan (#00FFFF).
@ DarkRed
Dark red / maroon (#800000).
@ DarkBlue
Dark blue / navy (#000080).
@ Indigo
Indigo / dark blue-purple (#333399).
@ DarkOlive
Dark olive (#333300).
@ Gray
Medium gray (#808080).
@ BrightGreen3
Bright green (duplicate of index 11).
@ LightMint
Light mint green (CCFFCC).
@ MediumBlue
Medium blue (#0066CC).
@ BrightGreen
Bright green (#00FF00).
@ Magenta
Magenta / Fuchsia (FF00FF).
@ DarkPurple
Dark purple (#660066).
@ LightCyan
Light cyan (CCFFFF).
@ DarkRose
Dark rose (#993366).
@ Turquoise
Turquoise (#33CCCC).
@ LightSkyBlue
Light sky blue (#99CCFF).
@ Salmon
Salmon pink (FF8080).
@ Red2
Red (duplicate of index 10).
@ StrongYellow
Strong yellow (FFFF00).
@ StrongMagenta
Strong magenta (FF00FF).
@ VeryDarkGreen
Very dark green (#003300).
@ DarkGreen
Dark green (#008000).
@ LightYellow
Light yellow (FFFFCC).
@ DarkViolet
Dark violet (#800080).
@ LightGray
Light gray / silver (C0C0C0).
@ DarkMaroon
Dark maroon (#800000).
@ LightCornflowerBlue
Light cornflower blue (#9999FF).
SrgbColor GetSrgbColor()
Gets the sRGB color representation of the indexed color.
const Value DefaultIndexedColor
Default indexed color (system foreground color).
IndexedColor(int colorIndex)
Constructor with specified indexed color index.
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
const string DefaultSystemForegroundColorArgb
Default ARGB value for system foreground color.
Class representing a generic sRGB color (with or without alpha channel).
Definition SrgbColor.cs:19
Class for exceptions regarding Style incidents.
Class providing static methods to parse string values to specific types or to print object as languag...
static string ToString(int input)
Transforms an integer to an invariant sting.