Learn how to create and access SmartArt in PowerPoint using C#: https://blog.aspose.com/2021/09/22/create-smartart-in-powerpoint-using-csharp/
Last active
September 22, 2021 15:14
-
-
Save aspose-com-gists/f69856d5e985b8c77904c541dd1b33f5 to your computer and use it in GitHub Desktop.
Create or Access SmartArt in PowerPoint using 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
// Load the presentation | |
using (Presentation pres = new Presentation("AccessSmartArtShape.pptx")) | |
{ | |
// Iterate through every shape inside desired slide | |
foreach (IShape shape in pres.Slides[0].Shapes) | |
{ | |
// Check if shape is of SmartArt type | |
if (shape is ISmartArt) | |
{ | |
// Typecast shape to SmartArt | |
ISmartArt smart = (ISmartArt)shape; | |
System.Console.WriteLine("Shape Name:" + smart.Name); | |
// Checking SmartArt Layout | |
//if (smart.Layout == SmartArtLayoutType.BasicBlockList) | |
//{ | |
// Console.WriteLine("Do some thing here...."); | |
//} | |
} | |
} | |
} |
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
// Load presentation | |
using (Presentation presentation = new Presentation("AccessSmartArtShape.pptx")) | |
{ | |
// Traverse through every shape inside first slide | |
foreach (IShape shape in presentation.Slides[0].Shapes) | |
{ | |
// Check if shape is of SmartArt type | |
if (shape is ISmartArt) | |
{ | |
// Typecast shape to SmartArt | |
ISmartArt smart = (ISmartArt)shape; | |
// Check SmartArt style | |
if (smart.QuickStyle == SmartArtQuickStyleType.SimpleFill) | |
{ | |
// Change SmartArt Style | |
smart.QuickStyle = SmartArtQuickStyleType.Cartoon; | |
} | |
// Check SmartArt color type | |
if (smart.ColorStyle == SmartArtColorType.ColoredFillAccent1) | |
{ | |
// Change SmartArt color type | |
smart.ColorStyle = SmartArtColorType.ColorfulAccentColors; | |
} | |
} | |
} | |
// Save Presentation | |
presentation.Save("ChangeSmartArtStyle_out.pptx", 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
// Create a presentation or load existing one | |
using (Presentation pres = new Presentation()) | |
{ | |
// Access the presentation slide | |
ISlide slide = pres.Slides[0]; | |
// Add SmartArt Shape | |
ISmartArt smart = slide.Shapes.AddSmartArt(0, 0, 400, 400, SmartArtLayoutType.BasicBlockList); | |
smart.AllNodes[0].TextFrame.Text = "First Block"; | |
smart.AllNodes[1].TextFrame.Text = "Second Block"; | |
// Save presentation | |
pres.Save("SimpleSmartArt_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment