Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 23, 2021 10:57
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/6a054076684197a0d28101bb2e71b30c to your computer and use it in GitHub Desktop.
Save aspose-com-gists/6a054076684197a0d28101bb2e71b30c to your computer and use it in GitHub Desktop.
Create or Access SmartArt in PowerPoint using Java
// Load presentation
Presentation pres = new Presentation("AccessSmartArtShape.pptx");
try {
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes())
{
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt)
{
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Check SmartArt Layout
if (smart.getLayout() == SmartArtLayoutType.BasicBlockList)
{
System.out.println("Do some thing here....");
}
}
}
} finally {
if (pres != null) pres.dispose();
}
// Load presentation
Presentation pres = new Presentation("SimpleSmartArt.pptx");
try {
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes())
{
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt)
{
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Check SmartArt style
if (smart.getQuickStyle() == SmartArtQuickStyleType.SimpleFill) {
// Change SmartArt Style
smart.setQuickStyle(SmartArtQuickStyleType.Cartoon);
}
// Check SmartArt color type
if (smart.getColorStyle() == SmartArtColorType.ColoredFillAccent1) {
// Change SmartArt color type
smart.setColorStyle(SmartArtColorType.ColorfulAccentColors);
}
}
}
// Save presentation
pres.save("ChangeSmartArtStyle.pptx", SaveFormat.Pptx);
} finally {
pres.dispose();
}
// Create a presentation or load existing one
Presentation pres = new Presentation();
try {
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add SmartArt shape
ISmartArt smart = slide.getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.BasicBlockList);
// Save presentation
pres.save("SimpleSmartArt.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment