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

Free Support Forum - aspose.com

Aspose.Grid - Color individual cells - not working

I have somewhat of a crisis here at my clients site. I implemented a change proposed by you to allow us to color inividual cells in the Aspose.Grid. We had to change existing (working) code because something had changed in either the latest Apose upgrade, or because we moved the dev platform to Vista.

PROBLEM: After the code below executes, we lose the values in the Aspose.Grid cells that were colored. The data is still in the dataset, and the Aspose.Grid binding method works, so the values are there.

Appartantly, the code below colors the cell but also renders the existing value invisible somehow.

Here is the code I am using now.

public void ColorDGCells(int _index, int _cell)


WebWorksheet sheet = dg.WebWorksheets[dg.ActiveSheetIndex];

Aspose.Grid.Web.TableItemStyle style1 = new Aspose.Grid.Web.TableItemStyle();

Aspose.Grid.Web.TableItemStyle style2 = new Aspose.Grid.Web.TableItemStyle();

style1.BackColor = Color.FromName("Yellow");

sheet.Cells[_index, 0].Style = style1;

style2.BackColor = Color.FromName("#FFC0CB");

style2.ForeColor = Color.FromName("Black");

sheet.Cells[_index, _cell].Style = style2;


What am I doing wrong here?

As I said, many people are upset because they think that all of their data is missing. Please help!


Eric Christianson

Hi Eric,

Thanks for considering Aspose.

Could you try to change your code in the way like (you should use this sample code after Worksheet.DataBind() method):

WebCells cells = sheet.Cells;
WebCell cell2 = sheet.Cells[2,5];
WebCell cell1 = sheet.Cells[0,0];
Aspose.Grid.Web.TableItemStyle style1 = new Aspose.Grid.Web.TableItemStyle();
// copy from the cell's style
style1.ForeColor = Color.Red;
style1.BackColor = Color.Yellow;
cell2.Style = style1;
Thank you.

Thank you, sir. That did the trick :-). Here is the code for anybody else who is trying to color individual cells in an Aspose.Grid. This method colors two different columns (A, B):

public void ColorGridCells(int _rowindex, int _Column_A_index, int _Column_B_index)


WebWorksheet sheet = dg.WebWorksheets[dg.ActiveSheetIndex];

Aspose.Grid.Web.TableItemStyle style1 = new Aspose.Grid.Web.TableItemStyle();

WebCells cells = sheet.Cells;

WebCell cellA = sheet.Cells[_rowindex, _Column_A_index];

WebCell cellB = sheet.Cells[_rowindex, _Column_B_index];


style1.BackColor = Color.Yellow;

cellA.Style = style1;


style1.ForeColor = Color.Black;

style1.BackColor = Color.FromName("#FFC0CB");

cellB.Style = style1;