Row BackGround Color

Hey all,

I am using Aspose.Cells version 3.2. I want to set the BackGroundColor of a certian row to black. I used the following code:

Excel objExcel = new Excel();

Worksheet worksheet = objExcel.Worksheets[0];

Cells objCells = worksheet.Cells;

objCells.Rows[2].Style.BackgroundColor = Color.Black; //Here I change the BackGround Color of the second row

objExcel.Save("Excel1.xls", FileFormatType.Default, SaveType.OpenInExcel, Response);

But this code doesn't seem to work. Is there anyway to change the color of a certain row??

Hi,

Since you are using the older version. Please try the latest version 4.3 (you may download from: `http://www.aspose.com/Community/Files/`) which is more enhanced and stable with a lots of new and advanced features added in it.

In the newer vesion please change your code, it will also enhance your performance in the long run:

//In the newer version Excel class has been renamed to Workbook.

Workbook objExcel = new Workbook();

Worksheet worksheet = objExcel.Worksheets[0];

Cells objCells = worksheet.Cells;

//Create a style object.

Style style = objExcel.Styles[objExcel.Styles.Add()];

style.ForegroundColor = Color.Black;

style.Pattern = BackgroundType.Solid;

//In the newer version the styleflag struct is added for setting specific format only.

StyleFlag flag = new StyleFlag();

flag.CellShading = true;

//Apply format to the second row.

objCells.Rows[1].ApplyStyle(style,flag);

objExcel.Save("Excel1.xls", FileFormatType.Default, SaveType.OpenInExcel, Response);

Thank you.