We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can I assign a custom color to a cell?

In the legacy (Excel Interop) code, this can be done to assign a custom color to a cell:

contractCell.Interior.Color = ColorTranslator.ToOle(Color.FromArgb(202, 134, 250));

Using Aspose Cells, I'm trying to find the corresponding way to do it. This code:

styleContractRow2.ForegroundColor = ColorTranslator.ToOle(Color.FromArgb(202, 134, 250));
styleContractRow2.Pattern = BackgroundType.Solid;

...does not compile, telling me, "*Cannot implicitly convert type 'int' to 'System.Drawing.Color'*"

So how can I assign a custom color?


Thanks for your posting and using Aspose.Cells.

Please see the following sample code that applies the custom color on cell C6. It should fulfill your requirements. I have also attached the output excel file generated with this code for a reference.

Workbook wb = new Workbook();

Worksheet ws = wb.Worksheets[0];

Cell c = ws.Cells[“C6”];

Style s = c.GetStyle();
s.Pattern = BackgroundType.Solid;
s.ForegroundColor = Color.FromArgb(202, 134, 250);