Set BackgroundColor in XSSFWorkbook with Java

陌路散爱 提交于 2020-06-29 04:22:50

问题


I want to set my own backgroundcolor in XSSFWorkbook. So far i have this code:

 style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128)));  
    styles.put("item_right", style);

But i got the following error:

The method setFillForegroundColor(short) in the type CellStyle is not >applicable for the arguments (XSSFColor)

The constructor XSSFColor(Color) is deprecated

So how can i set my own color in XSSFWorkbook ?


回答1:


One of the solution :

style.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128), null));

It's not deprecated with last version.



来源:https://stackoverflow.com/questions/55685471/set-backgroundcolor-in-xssfworkbook-with-java

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