I’m using Aspose.slides .NET and try to change the row background color in a table. Based on the samples, I should be able to set it with CellFormat.FillFormat.PatternFormat.ForeColor.Color. However, it just doesn’t change the default color no matter whether I tried with CellFormat or PortionFormat.
public static ITable AddTable(ISlide slide, float x, float y, double[] dblCols, double[] dblRows)
{
ITable table = slide.Shapes.AddTable(x, y, dblCols, dblRows);
table.FirstRow = true;
table.HorizontalBanding = false;
Color tableHeaderFillColor = Color.FromArgb(48, 158, 199); // Hex #309EC7
// setting first row cells' font height
PortionFormat portionFormat = new PortionFormat();
portionFormat.FontHeight = 14;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = Color.White;
**portionFormat.FillFormat.PatternFormat.ForeColor.Color = tableHeaderFillColor;**
table.Rows[0].SetTextFormat(portionFormat)
for (int n = 0; n < dblCols.Length; n++)
{
table[n, 0].TextAnchorType = TextAnchorType.Center;
}
// setting the rest row cells text color
portionFormat.FillFormat.SolidFillColor.Color = Color.Red;
background = table[1, 1].CellFormat.FillFormat.PatternFormat;
for (int i = 1; i < dblRows.Length; i++)
{
table.Rows[i].SetTextFormat(portionFormat);
for (int n = 0; n < dblCols.Length; n++)
{
//set text vertical alignment
table[n, i].TextAnchorType = TextAnchorType.Center;
//set border
table[n, i].CellFormat.BorderTop.FillFormat.FillType = FillType.NoFill;
table[n, i].CellFormat.BorderLeft.FillFormat.FillType = FillType.NoFill;
table[n, i].CellFormat.BorderBottom.FillFormat.FillType = FillType.Solid;
table[n, i].CellFormat.BorderBottom.FillFormat.SolidFillColor.Color = tableHeaderFillColor;
//set cell background color
**table[n, i].CellFormat.FillFormat.PatternFormat.ForeColor.Color = Color.White;**
}
}
return table;
}