Управление формой SmartArt
Создание формы SmartArt
Aspose.Slides для C++ теперь позволяет добавлять пользовательские формы SmartArt на слайды с нуля. Aspose.Slides для C++ предоставляет самый простой API для создания форм SmartArt самым простым способом. Чтобы создать форму SmartArt на слайде, выполните следующие шаги:
- Создайте экземпляр класса Presentation.
- Получите ссылку на слайд, используя его индекс.
- Добавьте форму SmartArt, установив тип компоновки (LayoutType).
- Запишите изменённую презентацию в файл 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); | |