管理SmartArt形状
创建SmartArt形状
Aspose.Slides for C++ 现在支持从头开始在幻灯片中添加自定义SmartArt形状。Aspose.Slides for C++提供了最简单的API,以最简便的方式创建SmartArt形状。要在幻灯片中创建SmartArt形状,请按照以下步骤进行操作:
- 创建一个 Presentation 类的实例。
- 通过使用其索引获取幻灯片的引用。
- 通过设置布局类型添加SmartArt形状。
- 将修改后的演示文稿写入PPTX文件。
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形状
以下代码将用于访问演示文稿幻灯片中添加的SmartArt形状。在示例代码中,我们将遍历幻灯片中的每个形状,并检查它是否为SmartArt形状。如果形状是SmartArt类型,则将其强制转换为SmartArt实例。
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()); | |
} | |
} | |
访问具有特定布局类型的SmartArt形状
以下示例代码将帮助访问具有特定布局类型的SmartArt形状。请注意,您不能更改SmartArt的布局类型,因为它是只读的,并且仅在添加SmartArt形状时设置。
- 创建一个
Presentation
类的实例,并加载具有SmartArt形状的演示文稿。 - 通过使用其索引获取第一个幻灯片的引用。
- 遍历第一个幻灯片中的每个形状。
- 检查形状是否为SmartArt类型,并在它是SmartArt时将所选形状强制转换为SmartArt。
- 检查具有特定布局类型的SmartArt形状,并执行所需的操作。
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形状样式
以下示例代码将帮助访问具有特定布局类型的SmartArt形状。
- 创建一个
Presentation
类的实例,并加载具有SmartArt形状的演示文稿。 - 通过使用其索引获取第一个幻灯片的引用。
- 遍历第一个幻灯片中的每个形状。
- 检查形状是否为SmartArt类型,并在它是SmartArt时将所选形状强制转换为SmartArt。
- 查找具有特定样式的SmartArt形状。
- 为SmartArt形状设置新样式。
- 保存演示文稿。
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形状颜色样式
在此示例中,我们将学习如何更改任何SmartArt形状的颜色样式。在以下示例代码中,将访问具有特定颜色样式的SmartArt形状并更改其样式。
- 创建一个
Presentation
类的实例,并加载具有SmartArt形状的演示文稿。 - 通过使用其索引获取第一个幻灯片的引用。
- 遍历第一个幻灯片中的每个形状。
- 检查形状是否为SmartArt类型,并在它是SmartArt时将所选形状强制转换为SmartArt。
- 查找具有特定颜色样式的SmartArt形状。
- 为SmartArt形状设置新颜色样式。
- 保存演示文稿。
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); | |