Class ExcelColor

java.lang.Object
com.northconcepts.datapipeline.excel.ExcelColor

public final class ExcelColor extends Object
Represents a color that can be used in Excel cells. Colors can be created from RGB values or from Excel color palette indexes. Provides methods to darken or lighten colors and convert between different color representations.
See Also:
  • Constructor Details

    • ExcelColor

      protected ExcelColor(Integer excelColorPaletteIndex, Integer red, Integer green, Integer blue)
      Creates an ExcelColor with the specified palette index and RGB components. This is a protected constructor used internally.
      Parameters:
      excelColorPaletteIndex - the Excel color palette index, may be null
      red - the red component (0-255), may be null
      green - the green component (0-255), may be null
      blue - the blue component (0-255), may be null
    • ExcelColor

      public ExcelColor(int red, int green, int blue)
      Creates an ExcelColor from RGB components. Automatically determines the corresponding Excel color palette index if available.
      Parameters:
      red - the red component (0-255)
      green - the green component (0-255)
      blue - the blue component (0-255)
  • Method Details

    • fromRgb

      public static ExcelColor fromRgb(byte[] rgb)
      Creates an ExcelColor from an RGB byte array.
      Parameters:
      rgb - a 3-byte array containing red, green, and blue components (0-255)
      Returns:
      an ExcelColor instance
      Throws:
      DataException - if rgb is null or does not contain exactly 3 bytes
    • fromIndex

      public static ExcelColor fromIndex(int index)
      Creates an ExcelColor from an Excel color palette index.
      Parameters:
      index - the Excel color palette index
      Returns:
      an ExcelColor instance, or null if the index is not in the palette
    • getExcelColorPaletteIndex

      public Integer getExcelColorPaletteIndex()
      Gets the Excel color palette index if this color matches a palette color.
      Returns:
      the palette index, or null if this color is not in the palette
    • getRed

      public Integer getRed()
      Gets the red component of this color.
      Returns:
      the red component (0-255), or null if not set
    • getGreen

      public Integer getGreen()
      Gets the green component of this color.
      Returns:
      the green component (0-255), or null if not set
    • getBlue

      public Integer getBlue()
      Gets the blue component of this color.
      Returns:
      the blue component (0-255), or null if not set
    • getRgb

      public Integer getRgb()
      Gets the RGB value as a single integer (0xRRGGBB format).
      Returns:
      the RGB value, or null if red is not set
    • getHex

      public String getHex()
      Gets the color as a hexadecimal string (e.g., "#RRGGBB").
      Returns:
      the hex color string, or null if red is not set
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • darken

      public ExcelColor darken(double factor)
      Darkens a color.
      Parameters:
      factor - a value between 0.0 and 1.0
      Returns:
      a new instance of ExcelColor with the factor applied.
    • lighten

      public ExcelColor lighten(double factor)
      Lightens a color.
      Parameters:
      factor - a value between 0.0 and 1.0
      Returns:
      a new instance of ExcelColor with the factor applied.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object