Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 22, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/f69856d5e985b8c77904c541dd1b33f5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/f69856d5e985b8c77904c541dd1b33f5 to your computer and use it in GitHub Desktop.
Create or Access SmartArt in PowerPoint using C#
// 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....");
//}
}
}
}
// 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);
}
// 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