Created
December 25, 2020 01:39
-
-
Save aspose-com-gists/ecd09cd095a7e1c2455ea53f54161b3e to your computer and use it in GitHub Desktop.
Work with Shapes in PowerPoint Slides in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Accessing shapes collection for selected slide | |
IShapeCollection shapes = pres.Slides[0].Shapes; | |
// Add autoshape Ellipse | |
IAutoShape ellipse = shapes.AddAutoShape(ShapeType.Ellipse, 0, 100, 100, 100); | |
// Add autoshape Rectangle | |
IAutoShape rectangle = shapes.AddAutoShape(ShapeType.Rectangle, 100, 300, 100, 100); | |
// Adding connector shape to slide shape collection | |
IConnector connector = shapes.AddConnector(ShapeType.BentConnector2, 0, 0, 10, 10); | |
// Joining Shapes to connectors | |
connector.StartShapeConnectedTo = ellipse; | |
connector.EndShapeConnectedTo = rectangle; | |
// Call reroute to set the automatic shortest path between shapes | |
connector.Reroute(); | |
// Save presentation | |
pres.Save("presentation.pptx", Export.SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Get the first slide | |
ISlide sld = pres.Slides[0]; | |
// Add autoshape of ellipse type | |
sld.Shapes.AddAutoShape(ShapeType.Ellipse, 50, 150, 150, 50); | |
// Save presentation | |
pres.Save("presentation.pptx", Export.SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Obtain shape collection from source slide | |
IShapeCollection sourceShapes = pres.Slides[0].Shapes; | |
ILayoutSlide blankLayout = pres.Masters[0].LayoutSlides.GetByType(SlideLayoutType.Blank); | |
ISlide destSlide = pres.Slides.AddEmptySlide(blankLayout); | |
// Get shape collection from destination slide | |
IShapeCollection destShapes = destSlide.Shapes; | |
destShapes.AddClone(sourceShapes[1], 50, 150 + sourceShapes[0].Height); | |
destShapes.AddClone(sourceShapes[2]); | |
// Clone shape | |
destShapes.InsertClone(0, sourceShapes[0], 50, 150); | |
// Save presentation | |
pres.Save("presentation.pptx", Export.SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a presentation file | |
using (Presentation pres = new Presentation("presentation.pptx")) | |
{ | |
// Get the first slide | |
ISlide sld = pres.Slides[0]; | |
// Add autoshape of rectangle type | |
IShape shp1 = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 40, 150, 50); | |
IShape shp2 = sld.Shapes.AddAutoShape(ShapeType.Moon, 160, 40, 150, 50); | |
String alttext = "User Defined"; | |
int iCount = sld.Shapes.Count; | |
for (int i = 0; i < iCount; i++) | |
{ | |
// Retrieve shape | |
AutoShape ashp = (AutoShape)sld.Shapes[0]; | |
if (String.Compare(ashp.AlternativeText, alttext, StringComparison.Ordinal) == 0) | |
{ | |
// Remove shape | |
sld.Shapes.Remove(ashp); | |
} | |
} | |
// Save presentation | |
pres.Save("presentation.pptx", Export.SaveFormat.Pptx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment