How to Remove Row or Column in Table

We have previously introduced how to insert a custom table and how to edit a table in PowerPoint documents. Now, we are going to make a brief introduction about how to remove the rows or columns that belong to an existing table.

Spire.Presentation for .NET, built to provide flexible PowerPoint document handling capabilities, allows developers to add a table to a slide and perform some basic operations as removing rows and columns in the table in an easy way.

Step 1: Create a PowerPoint instance and load a sample file.

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

Step 2: Find the table and remove the second column and second row.

ITable table = null;  
foreach (IShape shape in presentation.Slides[0].Shapes)
{
  if (shape is ITable)
  {
    table = (ITable)shape;
    table.ColumnsList.RemoveAt(1, false)    
    table.TableRows.RemoveAt(1, false);       
  }
}

Step 3: Save the document.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

The sample table with the second row and second column highlighted.

Remove Row or Column in Table

Result:

Remove Row or Column in Table

Full C# code:

using Spire.Presentation;

namespace RemoveRow
{

    class Program
    {

        static void Main(string[] args)
        {
            //create a PPT document
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("table.pptx");

            //get the table in PPT document
            ITable table = null;
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //remove the second column
                    table.ColumnsList.RemoveAt(1, false);

                    //remove the second row
                    table.TableRows.RemoveAt(1, false);
                }
            }
            //save the document
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }

    }
}