Cell background color not set

I’m trying to iterate over all cells and set cell background color depending on cell.StringValue:

Dim s As Style
s.BackgroundColor = System.Drawing.Color.Yellow
s.Font.IsBold = True
For Each c As Cell In sheet.Cells
 If c.StringValue = “OPEN” Then
c.SetStyle(s)
 End If
Next
The Bold property is set alright, however, the background property is not set.
What am I doing wrong?

Hi,

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 C# and VB.NET, please use this version or later::
Aspose.Cells for .NET v7.0.1.5

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

Please see the code example in C#, VB.NET and Java.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“C3”];


Style style = cell.GetStyle();

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = Color.Green;

cell.SetStyle(style);



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



VB.NET
Dim workbook As Workbook = New Workbook()

Dim worksheet As Worksheet = workbook.Worksheets(0)

Dim cell As Cell = worksheet.Cells("C3")

Dim style As Style = cell.GetStyle()
style.Pattern = BackgroundType.Solid
style.ForegroundColor = Color.Green
cell.SetStyle(style)

workbook.Save("F:\Shak-Data-RW\Downloads\output.xlsx")

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: