Removing row or column in Table in VSTO and Aspose.Slides

VSTO

Below is code for removing rows or columns from table using VSTO Presentation:


    string FileName = "Removing Row Or Column in Table.pptx";

   Presentation pres = Application.Presentations.Open(FileName);

   //Get the first slide

   Slide sld = pres.Slides[1];

   foreach (Shape shp in sld.Shapes)

   {

      if (shp.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)

      {

          shp.Table.Rows[1].Delete();

      }

   }

Aspose.Slides

Aspose.Slides for .NET has provided the simplest API to create tables in an easiest way. To create a table in a slide and perform some basic operations on the table, please follow the steps below:

  • Create an instance of Presentation class
  • Obtain the reference of a slide by using its Index
  • Define Array of Columns with Width
  • Define Array of Rows with Height
  • Add a Table to the slide using AddTable method exposed by IShapes object
  • Remove table row
  • Remove table column
  • Write the modified presentation as a PPTX file

   string FileName = "Removing Row Or Column in Table.pptx";

  Presentation MyPresentation = new Presentation(FileName);

  //Get First Slide

  ISlide sld = MyPresentation.Slides[0];

  foreach (IShape shp in sld.Shapes)

  if (shp is ITable)

  {

     ITable tbl = (ITable)shp;

     tbl.Rows.RemoveAt(0, false);

  }

  MyPresentation.Save(FileName,Export.SaveFormat.Pptx);


Download Running Code

Download Sample Code