vishnu
vishnu

Reputation: 197

How to resolve the "Cannot resolve constructor 'XSSFColor(Color)'"?

After upgrading apache.poi.version to 5.2.2, I get 'Cannot resolve constructor XSSFColor(Color)' error. Getting the error in below line of code.

protected final XSSFColor tdBlueColor = new XSSFColor(new java.awt.Color(51, 51, 153));

Please help, thanks in advance.

Upvotes: 2

Views: 2299

Answers (1)

PJ Fanning
PJ Fanning

Reputation: 1046

In POI 5.2.2, one of the most common ways to create an XSSFColor is:

IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
XSSFColor color = new XSSFColor(new byte[]{51, 51, (byte)153}, colorMap);

Or use Hex, like:

final String rgbS = "333399";
final byte[] rgbB = org.apache.commons.codec.binary.Hex.decodeHex(rgbS);
IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
XSSFColor color = new XSSFColor(rgbB, colorMap);

I used https://htmlcolorcodes.com/rgb-to-hex/?r=51&g=51&b=153 to convert the java.awt.Color values to Hex format (and got 333399)

Upvotes: 4

Related Questions