Aspose.excel - color

I was trying to format background with color, but got all Black

Dim excel As Aspose.Excel.Excel

excel = New Aspose.Excel.Excel

excel.Open("C:\sample.xls")

Dim w As Aspose.Excel.Worksheet = excel.Worksheets(0)

For i As Int32 = 1 To 50

w.Cells(15, i).Style.ForegroundColor = System.Drawing.Color.FromArgb(230, 229, 229)

w.Cells(17, i).Style.ForegroundColor = System.Drawing.Color.AliceBlue

Next

excel.Save("c:\ee1.xls")

System.Diagnostics.Process.Start("c:\ee1.xls")

I am using 3.5.0.3

Since you use colors not in standard palette, please add them to palette first. Please check Color and Palette for detail information.

@me2005,

For XLS file format, you need to add your desired custom color (other than default colors (e.g. red, blue, green, yellow and so on… etc.)) to MS Excel color palette first, so that you could set your desired background color accordingly. For your information, for XLS file format, only 56 colors (0 - 55 indexed) are there on standard color palette (of MS Excel 97-2003). For advanced file formats, e.g. XLSX, XLSB, XLSM, etc.(MS Excel 2007, 2010, 2013, 2015, Excel 365) you do not need to perform this step as these file formats have unlimited colors on the palette.

Please note, Aspose.Excel was obsoleted and discontinued. It has been replaced by Aspose.Cells which is more advanced and feature-rich API. Using Aspose.Cells, you may easily apply formatting to cells with its data in all MS Excel (97-2003, 2007, 2010, 2013, 2015, 2019/365, etc.) file formats.

Please see the following sample code on how to set background color of cell(s) in the worksheet for your reference
e.g.
Sample code:

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();

// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];

// Define a Style and get the A1 cell style
Style style = worksheet.Cells["A1"].GetStyle();

// Setting the foreground color to yellow
style.ForegroundColor = Color.Yellow;

// Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;

// Apply the style to A1 cell
worksheet.Cells["A1"].SetStyle(style);

// Get the A2 cell style
style = worksheet.Cells["A2"].GetStyle();

// Setting the foreground color to blue
style.ForegroundColor = Color.AliceBlue;

// Setting the background color to yellow
style.BackgroundColor = Color.Yellow;

// Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;

// Apply the style to A2 cell
worksheet.Cells["A2"].SetStyle(style);

// Saving the Excel file
workbook.Save("book1.out.xlsx");

See the following link that contains multiple examples on cell formatting:
Apply Cells Formatting

Get the latest version of the product here:
Aspose.Cells for .NET (Latest Version)

You may also download Examples (project) here which contains number of ready to run examples.