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

不羁岁月 提交于 2019-12-19 07:23:10

问题


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!


回答1:


It would appear that it is not possible. boo. This was the best explanation of why:

http://osdir.com/ml/user-poi.apache.org/2009-03/msg00034.html




回答2:


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.




回答3:


As commented by Piotr,
to color tabs in POI 3.11 i had to use:

import org.apache.poi.ss.usermodel.IndexedColors;
sheet.setTabColor(IndexedColors.BLACK.getIndex());

(Note that it is "IndexedColors", not "IndexedColor" like showed by Piotr.)
here is a list showing the colors: http://jlcon.iteye.com/blog/1122538



来源:https://stackoverflow.com/questions/2093777/how-to-change-the-tab-color-of-a-worksheet-with-apache-poi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!