Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. There is a document in our website introducing you how to insert table. And in this document, I will introduce you how to remove tables within a PPT document.
Step 1: Create Presentation instance and load file.
Presentation presentation = new Presentation(); presentation.LoadFromFile("sample.ppt");
Step 2: Get the tables within the PPT document.
List shape_tems = new List(); foreach (IShape shape in presentation.Slides[0].Shapes) { if (shape is ITable) { //add new table to table list shape_tems.Add(shape); } }
Step 3: Remove all tables.
foreach (IShape shape in shape_tems) { presentation.Slides[0].Shapes.Remove(shape); }
Step 4: Save the document.
presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
Download and install Spire.Presentation for .NET and refer to below code to remove tables within PPT document.
Screenshots:
Before:
After:
Full Code:
//create Presentation instance and load file Presentation presentation = new Presentation(); presentation.LoadFromFile("sample.ppt"); //get the tables in PowerPoint document List shape_tems = new List(); foreach (IShape shape in presentation.Slides[0].Shapes) { if (shape is ITable) { //add new table to table list shape_tems.Add(shape); } } //remove all tables foreach (IShape shape in shape_tems) { presentation.Slides[0].Shapes.Remove(shape); } //save the document presentation.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx");
'create Presentation instance and load file Dim presentation As New Presentation() presentation.LoadFromFile("sample.ppt") 'get the tables in PowerPoint document Dim shape_tems As New List(Of IShape)() For Each shape As IShape In presentation.Slides(0).Shapes If TypeOf shape Is ITable Then 'add new table to table list shape_tems.Add(shape) End If Next 'remove all tables For Each shape As IShape In shape_tems presentation.Slides(0).Shapes.Remove(shape) Next 'save the document presentation.SaveToFile("result.pptx", FileFormat.Pptx2010) System.Diagnostics.Process.Start("result.pptx")
If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.