I am trying to set the background color of a worksheet tab using Apache POI. I can't seem to figure out how to set the style on the tabs themselves though.
Thanks for the help!
To change the color of a sheet tab, right-click the tab, point to Tab Color and pick a color that you want. Tip: Click away from the formatted tab to see the new tab color. If you want to remove the color, right-click the tab, point to Tab Color, and pick No Color.
Apache POI provides three methods for changing the background color. In the CellStyle class, we can use the setFillForegroundColor, setFillPattern, and setFillBackgroundColor methods for this purpose. A list of colors is defined in the IndexedColors class. Similarly, a list of patterns is defined in FillPatternType.
Right-click the worksheet tab whose color you want to change. Choose Tab Color, and then select the color you want. The color of the tab changes, but not the color of the font. When you choose a dark tab color, the font switches to white, and when you choose a light color for the tab, the font switches to black.
As commented by Alfabravo... it's possible now to change the XSSFSheet
tab color.
sheet.setTabColor(int colorIndex)
is used for that, and so if we use
sheet.setTabColor(num);
num = 0
: set Black Color in tab.
num = 1
: set White Color in tab.
num = 2
: set Red Color in tab.
num = 3
: set Green Color in tab.
num = 4
: set Blue Color in tab.
num = 5
: set Yellow Color in tab.
and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With