Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Colors in Apache POI

How can we add custom colors (HEX or RGB) to a SXSSFWorkbook? I found multiple implementations where everyone used HSSFPalette to change the custom palette of a HSSFWorkbook. But unlike HSSFWorkbook, SXSSFWorkbook doesn't have a getCustomPalette call and therefore I couldn't get any palette to override. Any pointers?

like image 313
Leo Avatar asked Mar 23 '23 10:03

Leo


1 Answers

An SXSSFWorkbook is a wrapper around a XSSFWorkbook. Because it's just XSSF, you can directly create an XSSFColor with any RGB you want. You don't need to override any palette.

XSSFColor customColor = new XSSFColor(new byte[] {alpha, red, green, blue});

You can also pass a java.awt.Color if you want.

XSSFColor anotherColor = new XSSFColor(new java.awt.Color(red, green, blue, alpha));
like image 137
rgettman Avatar answered Apr 05 '23 07:04

rgettman