News Category

How to Set and Remove Table Border in PowerPoint

2016-01-15 03:41:19 Written by  support iceblue
Rate this item
(0 votes)

Borders can make the associative perception of a table stronger, but sometimes, especially in PowerPoint, you may want to remove them in order to achieve a better visual effect. In this part, we're going to introduce how to set and remove border of an existing table in PowerPoint by using Spire.Presentation for .NET.

Before start, please download and install Spire.Presentation correctly, after that add the Spire.Presentation.dll file as the reference of your project.

Detail steps overview:

Set table border:

Step 1: Create a new presentation instance and load the sample document from file.

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

Step 2: Find the table by looping through all the slides, and then set borders for it. Users can set different border styles according to their requirements.

foreach (ISlide slide in presentation.Slides)
{
    foreach (IShape shape in slide.Shapes)
    {
        if (shape is ITable)
        {
            foreach (TableRow row in (shape as ITable).TableRows)
            {
                foreach (Cell cell in row)
                {
                    cell.BorderTop.FillType = FillFormatType.Solid;
                    cell.BorderBottom.FillType = FillFormatType.Solid;
                    cell.BorderLeft.FillType = FillFormatType.Solid;
                    cell.BorderRight.FillType = FillFormatType.Solid;
                }
            }
        }
    }
}

Step 3: Save the file as Border.pptx.

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

Remove table border:

Remove table border is very simple, refer to the following codes:

cell.BorderTop.FillType = FillFormatType.None;
cell.BorderBottom.FillType = FillFormatType.None;
cell.BorderLeft.FillType = FillFormatType.None;
cell.BorderRight.FillType = FillFormatType.None;

Effective screenshots:

Before:

How to Set and Remove Table Border in PowerPoint

After:

How to Set and Remove Table Border in PowerPoint

Full codes:

using Spire.Presentation;
using Spire.Presentation.Drawing;

namespace Set_and_Remove_Table_Border_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("testTable.pptx");
            foreach (ISlide slide in presentation.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    if (shape is ITable)
                    {
                        foreach (TableRow row in (shape as ITable).TableRows)
                        {
                            foreach (Cell cell in row)
                            {
                                //Add top border and set its FillType as Solid.
                                cell.BorderTop.FillType = FillFormatType.Solid;
                                //Remove top border
                                //cell.BorderTop.FillType = FillFormatType.None;

                                cell.BorderBottom.FillType = FillFormatType.Solid;
                                //cell.BorderBottom.FillType = FillFormatType.None;

                                cell.BorderLeft.FillType = FillFormatType.Solid;
                                //cell.BorderLeft.FillType = FillFormatType.None;

                                cell.BorderRight.FillType = FillFormatType.Solid;
                                //cell.BorderRight.FillType = FillFormatType.None;
                            }
                        }
                    }
                }
            }
            presentation.SaveToFile("Border.pptx", FileFormat.Pptx2010);
        }
    }
}

Additional Info

  • tutorial_title: Set and Remove Table Border in PowerPoint
Last modified on Friday, 24 September 2021 09:22