Package org.apache.poi.hssf.usermodel
Class HSSFPalette
java.lang.Object
org.apache.poi.hssf.usermodel.HSSFPalette
Represents a workbook color palette.
Internally, the XLS format refers to colors using an offset into the palette
record. Thus, the first color in the palette has the index 0x8, the second
has the index 0x9, etc. through 0x40
-
Method Summary
Modifier and TypeMethodDescriptionaddColor
(byte red, byte green, byte blue) Adds a new color into an empty color slot.findColor
(byte red, byte green, byte blue) Finds the first occurrence of a given colorfindSimilarColor
(byte red, byte green, byte blue) Finds the closest matching color in the custom palette.findSimilarColor
(int red, int green, int blue) Finds the closest matching color in the custom palette.getColor
(int index) Retrieves the color at a given indexgetColor
(short index) Retrieves the color at a given indexvoid
setColorAtIndex
(short index, byte red, byte green, byte blue) Sets the color at the given offset
-
Method Details
-
getColor
Retrieves the color at a given index- Parameters:
index
- the palette index, between 0x8 to 0x40 inclusive- Returns:
- the color, or null if the index is not populated
-
getColor
Retrieves the color at a given index- Parameters:
index
- the palette index, between 0x8 to 0x40 inclusive- Returns:
- the color, or null if the index is not populated
-
findColor
Finds the first occurrence of a given color- Parameters:
red
- the RGB red component, between 0 and 255 inclusivegreen
- the RGB green component, between 0 and 255 inclusiveblue
- the RGB blue component, between 0 and 255 inclusive- Returns:
- the color, or null if the color does not exist in this palette
-
findSimilarColor
Finds the closest matching color in the custom palette. The method for finding the distance between the colors is fairly primative.- Parameters:
red
- The red component of the color to match.green
- The green component of the color to match.blue
- The blue component of the color to match.- Returns:
- The closest color or null if there are no custom colors currently defined.
-
findSimilarColor
Finds the closest matching color in the custom palette. The method for finding the distance between the colors is fairly primative.- Parameters:
red
- The red component of the color to match.green
- The green component of the color to match.blue
- The blue component of the color to match.- Returns:
- The closest color or null if there are no custom colors currently defined.
-
setColorAtIndex
public void setColorAtIndex(short index, byte red, byte green, byte blue) Sets the color at the given offset- Parameters:
index
- the palette index, between 0x8 to 0x40 inclusivered
- the RGB red component, between 0 and 255 inclusivegreen
- the RGB green component, between 0 and 255 inclusiveblue
- the RGB blue component, between 0 and 255 inclusive
-
addColor
Adds a new color into an empty color slot.- Parameters:
red
- The red componentgreen
- The green componentblue
- The blue component- Returns:
- The new custom color.
- Throws:
RuntimeException
- if there are more more free color indexes.
-