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

Free Support Forum - aspose.com

Cell color is always black

I’m trying to set the color of a cell using vb:

tmpStyle.ForegroundColor = System.Drawing.Color.FromArgb(210,219,230)

The cellcolor just turns up black, no matter what value I enter - except white.

The Aspose.Excel is version

*I tried searching the forum-site for: ForegroundColor, but I get a: Page cannot be found with URL: http://forums.aspose.com/Search/default.aspx&searchText=backgroundcolor&forum=9


Please refer to http://www.aspose.com/Products/Aspose.Excel/Api/Aspose.Excel.Excel.ChangePalette.html.

If the color is not in the MS Excel standard palette, you have to use the Excel.ChangePalette method to change the palette first.

excel.ChangePalette(System.Drawing.Color.FromArgb(210,219,230), 55)

tmpStyle.ForegroundColor = System.Drawing.Color.FromArgb(210,219,230)

Thank you - that was it.

This is to inform you that Aspose.Excel is discontinued now and a new product Aspose.Cells is introduced which contains all the legacy features as well as supports the latest features available in the recent versions of MS Excel. Using this new product you can work with colours and cells formatting in a variety of ways. Here is an example which shows how to set colours and background patterns.

// 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

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

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

// 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

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

Following is a detailed article which provides information about formatting cells in a workbook :
Cells Formatting

We have prepared a working solution which contains a vast range of examples that can be downloaded here.

Here you can find the download link to the latest version of this new product:
Aspose.Cells for .NET (Latest Version)