SmartArt-Form verwalten

SmartArt-Form erstellen

Aspose.Slides für C++ ermöglicht es nun, benutzerdefinierte SmartArt-Formen von Grund auf in ihren Folien hinzuzufügen. Aspose.Slides für C++ bietet die einfachste API, um SmartArt-Formen auf die einfachste Weise zu erstellen. Um eine SmartArt-Form in einer Folie zu erstellen, folgen Sie bitte den folgenden Schritten:

  • Erstellen Sie eine Instanz der Presentation Klasse.
  • Erhalten Sie die Referenz einer Folie, indem Sie ihren Index verwenden.
  • Fügen Sie eine SmartArt-Form hinzu, indem Sie den Layouttyp festlegen.
  • Schreiben Sie die modifizierte Präsentation als PPTX-Datei.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/SimpleSmartArt_out.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// Add SmartArt BasicProcess
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::BasicBlockList);
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

SmartArt-Form in der Folie zugreifen

Der folgende Code wird verwendet, um auf die in der Präsentationsfolie hinzugefügten SmartArt-Formen zuzugreifen. Im Beispielcode werden wir jede Form in der Folie durchlaufen und prüfen, ob es sich um eine SmartArt-Form handelt. Wenn die Form vom Typ SmartArt ist, werden wir sie in eine SmartArt-Instanz umwandeln.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SmartArt.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Traverse through every shape inside first slide
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++)
{
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x);
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape);
System::Console::WriteLine(u"Smart Art Name = " + smart->get_Name());
}
}

Auf SmartArt-Form mit bestimmtem Layouttyp zugreifen

Der folgende Beispielcode hilft, auf die SmartArt-Form mit einem bestimmten Layouttyp zuzugreifen. Bitte beachten Sie, dass Sie den Layouttyp der SmartArt nicht ändern können, da er schreibgeschützt ist und nur festgelegt wird, wenn die SmartArt-Form hinzugefügt wird.

  • Erstellen Sie eine Instanz der Presentation Klasse und laden Sie die Präsentation mit der SmartArt-Form.
  • Erhalten Sie die Referenz der ersten Folie, indem Sie ihren Index verwenden.
  • Durchlaufen Sie jede Form in der ersten Folie.
  • Überprüfen Sie, ob die Form vom Typ SmartArt ist, und wandeln Sie die ausgewählte Form in SmartArt um, wenn sie SmartArt ist.
  • Überprüfen Sie die SmartArt-Form mit einem bestimmten Layouttyp und führen Sie aus, was danach erforderlich ist.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SmartArt.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Traverse through every shape inside first slide
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++)
{
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x);
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape);
System::Console::WriteLine(u"Smart Art Name = " + smart->get_Name());
// Checking SmartArt Layout
if (smart->get_Layout() == SmartArtLayoutType::BasicBlockList)
{
System::Console::WriteLine(u"Do some thing here....");
}
}
}

SmartArt-Formstil ändern

Der folgende Beispielcode hilft, auf die SmartArt-Form mit einem bestimmten Layouttyp zuzugreifen.

  • Erstellen Sie eine Instanz der Presentation Klasse und laden Sie die Präsentation mit der SmartArt-Form.
  • Erhalten Sie die Referenz der ersten Folie, indem Sie ihren Index verwenden.
  • Durchlaufen Sie jede Form in der ersten Folie.
  • Überprüfen Sie, ob die Form vom Typ SmartArt ist, und wandeln Sie die ausgewählte Form in SmartArt um, wenn sie SmartArt ist.
  • Finden Sie die SmartArt-Form mit einem bestimmten Stil.
  • Setzen Sie den neuen Stil für die SmartArt-Form.
  • Speichern Sie die Präsentation.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SmartArt.pptx";
const String outPath = u"../out/ChangeSmartArtStyle_out.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Traverse through every shape inside first slide
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++)
{
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x);
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape);
// Checking SmartArt style
if (smart->get_QuickStyle() == SmartArtQuickStyleType::SimpleFill)
{
// Changing SmartArt Style
smart->set_QuickStyle(SmartArtQuickStyleType::Cartoon);
}
}
}
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

SmartArt-Formfarbstil ändern

In diesem Beispiel lernen wir, den Farbstil für eine beliebige SmartArt-Form zu ändern. Im folgenden Beispielcode wird auf die SmartArt-Form mit einem bestimmten Farbstil zugegriffen und ihr Stil geändert.

  • Erstellen Sie eine Instanz der Presentation Klasse und laden Sie die Präsentation mit der SmartArt-Form.
  • Erhalten Sie die Referenz der ersten Folie, indem Sie ihren Index verwenden.
  • Durchlaufen Sie jede Form in der ersten Folie.
  • Überprüfen Sie, ob die Form vom Typ SmartArt ist, und wandeln Sie die ausgewählte Form in SmartArt um, wenn sie SmartArt ist.
  • Finden Sie die SmartArt-Form mit einem bestimmten Farbstil.
  • Setzen Sie den neuen Farbstil für die SmartArt-Form.
  • Speichern Sie die Präsentation.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String templatePath = u"../templates/SmartArt.pptx";
const String outPath = u"../out/ChangeSmartArtShapeColorStyle.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Traverse through every shape inside first slide
for (int x = 0; x < pres->get_Slides()->idx_get(0)->get_Shapes()->get_Count(); x++)
{
SharedPtr<IShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(x);
if (System::ObjectExt::Is<Aspose::Slides::SmartArt::SmartArt>(shape))
{
System::SharedPtr<Aspose::Slides::SmartArt::SmartArt> smart = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArt>(shape);
if (smart->get_ColorStyle() == SmartArtColorType::ColoredFillAccent1)
{
// Changing SmartArt color type
smart->set_ColorStyle(SmartArtColorType::ColorfulAccentColors);
}
}
}
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);