News Category

How to fill the table cell with color in PowerPoint document in C#

2014-10-13 08:24:52 Written by  support iceblue
Rate this item
(0 votes)

A table provides a visual grouping of information and gives more convenience for writer to modify and query data in table. In particular when you have a table with colorful cells, your document would be more attractive. With the help of Spire.Presentation, developers can easily add tables and set table styles in PowerPoint document. This tutorial shows you how to fill the table cells with color in C#.

Step 1: Create a presentation document and load the file from disk.

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");

Step 2: Fill the table cell with color. You can fill all the cells or only fill one single row of cell in table with color.

foreach (TableRow row in table.TableRows)
  {
     foreach (Cell cell in row)
    {
      cell.FillFormat.FillType = FillFormatType.Solid;
      cell.FillFormat.SolidColor.Color = Color.Green;
     }
  }

Step 3: Save the presentation documents to file.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);

Effective screenshot for fill the color in all the table cells:

How to fill the table cell with color in PowerPoint document in C#

Effective screenshot for fill the color for the first row of table cell:

How to fill the table cell with color in PowerPoint document in C#

Full codes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace colorfilltablecell
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("sample.pptx");
            ITable table = null;
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    foreach (TableRow row in table.TableRows)

                    {
                        //TableRow row = table.TableRows[0];
                        foreach (Cell cell in row)
                        {
                            cell.FillFormat.FillType = FillFormatType.Solid;
                            cell.FillFormat.SolidColor.Color = Color.Green;
                        }
                    }
                }
            }
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
        }
    }
}

Additional Info

  • tutorial_title: Fill the table cell with color
Last modified on Friday, 24 September 2021 09:22