[]
        
(Showing Draft Content)

ColorUtilities

Class ColorUtilities

java.lang.Object
com.grapecity.documents.excel.ColorUtilities

public final class ColorUtilities extends Object
Provides utility methods for working with colors.

This class converts color strings into Color objects that can be used in the APIs such as cell fill and border formatting. Use stringToColor(String) to create colors from standard color names, RGB and RGBA expressions, and hexadecimal color strings.


 Color fillColor = ColorUtilities.stringToColor("rgba(255,0,0,0.5)");
 Color borderColor = ColorUtilities.stringToColor("#000000");
 worksheet.getRange("B2").getInterior().setColor(fillColor);
 worksheet.getRange("B2").getBorders().setColor(borderColor);
 
  • Constructor Details

    • ColorUtilities

      public ColorUtilities()
  • Method Details

    • stringToColor

      public static Color stringToColor(String colorString)
      Converts a color string to a Color object.

      Supported formats include RGB expressions such as "rgb(255,0,0)", RGBA expressions such as "rgba(255,0,0,0.5)", hexadecimal values such as "#F00" and "#FF0000", hexadecimal values with alpha such as "#F00C" and "#FF0000CC", and predefined color names such as "red".

      If the input cannot be parsed, this method returns a fully transparent color.

      
       Color fillColor = ColorUtilities.stringToColor("rgba(255,0,0,0.5)");
       worksheet.getRange("B2").getInterior().setColor(fillColor);
       
      Parameters:
      colorString - The color string to convert. This value may be null; if it cannot be parsed, a fully transparent color is returned.
      Returns:
      The Color represented by colorString. Returns a fully transparent color if parsing fails.