Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the tab color of a worksheet with Apache Poi

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!

like image 958
Casey Avatar asked Jan 19 '10 13:01

Casey


People also ask

How do you change the color of a worksheet tab?

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.

How do I change the color in Apache POI?

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.

Is it possible to change the color and font of the sheet tabs?

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.


1 Answers

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.

like image 194
Sankumarsingh Avatar answered Sep 28 '22 02:09

Sankumarsingh