Change foreground color

I'm trying to change the foreground color of some individual cells within a sheet. It looks like I should be able to just reference the property and change it, but it doesn't work. The code I'm using is:

For x As Integer = 8 To nLastRow
For y As Integer = 1 To nLastCol
If wb.Worksheets("Daily Data").Cells(x, y).StringValue <> wb.Worksheets("Daily Data SQL").Cells(x, y).StringValue Then
wb.Worksheets("Daily Data").Cells(x, y).Style.ForegroundColor = Color.Yellow
End If
Next
Next

The cell already has a value, so all I want to do is highlight differences without affecting the font or numeric formatting. However, running the above code does not appear to do anything (no cell colors are changed).

Rick

Hi Rick,

Thank you for considering Aspose.

Well, you have to set the Style.Pattern property whenever you are setting the foreground or background color. Please see the following documentation link in this regard,

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/colors-background-patterns.html

Also, please see the update code,

For x As Integer = 8 To nLastRow

For y As Integer = 1 To nLastCol

If wb.Worksheets("Daily Data").Cells(x, y).StringValue <> wb.Worksheets("Daily Data SQL").Cells(x, y).StringValue Then

wb.Worksheets("Daily Data").Cells(x, y).Style.ForegroundColor = Color.Yellow

'Setting the background pattern of the "A2" cell to vertical stripe

wb.Worksheets("Daily Data").Cells(x, y).Style.Pattern = BackgroundType.Solid

End If

Next

Next

Thank You & Best Regards,

Thanks for the quick response, your support is really great, and it now works.

It seems like I have problems with the online documentation, mostly in finding things. In this case, I did find style, but there are no examples in setting any of the properties. Assuming I'm looking at the correct property, it also says:

NOTE: This member is now obsolete. Instead, you should use GetStyle and SetStyle for the same purpose. These two new methods optimize speed and memory usage for applying formattings on a large amount of cells. This property will be removed 12 months later since March 2008. Aspose apologizes for any inconvenience you may have experienced.

(from http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/aspose.cells.cell.style.html)

Rick

Hi Rick,

Thanks for pointing it out.

Actually the page http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/aspose.cells.cell.style.html needs to be corrected and we will do it soon.

For your info, we did announce about removing the Style property of Cell class but later on some users insisted to retain this property. So we could not do it straight away. We will check it now and update you soon regarding it.

For your further reference, we recommend you to check an article at the moment: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/evaluating-cell-getstyle-setstyle-methods-against-cell-style-property.html

Thank you.