Free Support Forum - aspose.com

Background color with tables doesn't seem to work- what's wrong with this code?

What's wrong with this code ? it doesn't work I obtain only a red simple table, and I want a table with alternate color for each row.... can you please tell me what's wrong with this code ? it becomes urgent....

private void Button3_Click(object sender, System.EventArgs e)

{

System.IO.FileStream fis = new System.IO.FileStream(MapPath(".") + "\\result.ppt", System.IO.FileMode.Open, System.IO.FileAccess.Read);

Presentation pres = new Presentation(fis);

fis.Close();

Slide slide = pres.GetSlideByPosition(1);

Aspose.Slides.Table t = slide.Shapes.AddTable(0, 0, 1000, 1000, 3, 5, 2.0, Color.Red);

// color switcher to alternate the backcolor

bool colorSwitch =false;

// Add 3 new rows to the table to test the color switcher

t.AddRow();

t.AddRow();

t.AddRow();

// Delete last added row

//t.DeleteRow(t.RowsNumber - 1);

// Replace text in the cells

for (int ii = 0; ii < t.ColumnsNumber; ii++)

{

// Skip first row because it's a header

for (int jj = 1; jj < t.RowsNumber; jj++)

{

//setting the background color of the current cell

Aspose.Slides.Cell cell = null;

cell = t.GetCell(ii, jj);

if (cell != null)

{

if (colorSwitch)

{

cell.FillFormat.Type = FillType.Solid;

cell.FillFormat.BackColor = System.Drawing.Color.FromArgb(234,234,234);

}

else

{

cell.FillFormat.Type = FillType.Solid;

cell.FillFormat.BackColor = System.Drawing.Color.White ;

}

colorSwitch = !colorSwitch; //switch the color for the next row

}

}//rows

}//cols

this.Response.ContentType = "application/vnd.ms-powerpoint";

this.Response.AppendHeader("Content-Disposition", "attachment; filename=result.ppt");

this.Response.Flush();

System.IO.Stream st = this.Response.OutputStream;

//

// Write the file

//

pres.Write(st);

this.Response.End();

}

You change BackColor property instead of ForeColor. Your code should be:

if (colorSwitch)

{

cell.FillFormat.Type = FillType.Solid;

cell.FillFormat.ForeColor = System.Drawing.Color.FromArgb(234,234,234);

}

else

{

cell.FillFormat.Type = FillType.Solid;

cell.FillFormat.ForeColor = System.Drawing.Color.White ;

}


thanks for your fast response, I tested the forecolor property and it works !!! but I still don't understand why the backcolor property doesn't work, does that mean that if there's no text in one cell so this cell won't be the same color of the other cells of this row ??

Anyway, thank you for your support :)

ForeColor property is the main color of cell’s background. It’s not a color of text.
BackColor is additional color of background. It’s used for gradients and patterns only.