Change background color of worksheet cell with Aspose.Cells for Java

Hello, we recently migrated from aspose-cells 2.5.0 to aspose-cells 7.1.1.4

This was working just fine with aspose-cells 2.5.0

Please advise

Thanks

try {
com.aspose.cells.Workbook workbook = new Workbook();
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.get(0);

Cells cells = worksheet.getCells();
Cell cell = cells.get(0, 0);
cell.putValue("Hello");
Style style = cell.getStyle();
style.setBackgroundColor(Color.getRed());
cell.setStyle(style);

FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();

response.setHeader("Content-disposition", "attachment; filename=testFlow.xlsx");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

workbook.save(response.getOutputStream(), FileFormatType.XLSX);
ctx.responseComplete();

} catch (Exception e) {
logger.log(Level.SEVERE, "Test Report Failed", e);
}

Hi,

You need to use Style.setForegroundColor() method instead.

Please see this code below. It sets the background color of cell C3 to green. I have attached the output xlsx file and the screenshot.

For Java , please use this version or later:
Aspose.Cells
for Java v7.1.1.4



Please see the code example in Java.

Java


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.getWorksheets().get(0);


Cell cell = worksheet.getCells().get(“C3”);


Style style = cell.getStyle();

style.setPattern(BackgroundType.SOLID);

style.setForegroundColor(Color.getGreen());

cell.setStyle(style);


workbook.save(“F:\Shak-Data-RW\Downloads\output.xlsx”);



Screenshot:
Hi,

Also, we recommend you to kindly see the documentation especially the page for your reference:
http://docs.aspose.com/display/cellsjava/Colors++and++Background+Patterns

thank you.