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:
Effective screenshot for fill the color for the first row of table cell:
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); } } }