How to change background color of table cell of ppt using c# code?

How to change background color of table cell of ppt using c# code?



//creating powerpoint application
PowerPoint.Application pptApp = new PowerPoint.Application();
pptApp.Visible = Office.MsoTriState.msoTrue;
var pptPresent = pptApp.Presentations;
var fileOpen = pptPresent.Open(@file, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue);
// getting first slide
PowerPoint.Slide objSlide = fileOpen.Slides[1];
PowerPoint.Shapes item = objSlide.Shapes;
// getting first shape
var shape1 = item[1];
// check if shape is table
if (shape1.HasTable == Office.MsoTriState.msoTrue)
{
    // change the table cell to red color
    shape1.Table.Cell(2, 5).Shape.Fill.BackColor.RGB = System.Drawing.Color.Red.ToArgb();
    // make it visible
    shape1.Fill.Visible = Office.MsoTriState.msoTrue;
}
// saving the ppt
fileOpen.SaveAs(openFolder + subStr + ".pptx",PowerPoint.PpSaveAsFileType.ppSaveAsDefault,Office.MsoTriState.msoTrue);
// close the ppt
fileOpen.Close();

if (shape1.HasTable == Office.MsoTriState.msoTrue)
{
    // change the table cell to red color
    shape1.Table.Cell(2, 5).Shape.Fill.BackColor = System.Drawing.Color.Red; // modification here
    // make it visible
    shape1.Fill.Visible = Office.MsoTriState.msoTrue;
}


Learn More :