Управление узлом SmartArt
Добавить узел SmartArt
Aspose.Slides для C++ предоставил самый простой API для управления фигурами SmartArt самым простым способом. Следующий пример кода поможет добавить узел и дочерний узел внутри фигуры SmartArt.
- Создайте экземпляр класса Presentation и загрузите презентацию с фигурой SmartArt.
- Получите ссылку на первый слайд, используя его индекс.
- Пройдите через каждую фигуру на первом слайде.
- Проверьте, является ли фигура типом SmartArt, и если это SmartArt, выполните приведение типа выбранной фигуры к SmartArt.
- Добавьте новый узел в коллекцию узлов фигуры SmartArt и задайте текст в TextFrame.
- Теперь добавьте дочерний узел в недавно добавленный узел SmartArt и задайте текст в TextFrame.
- Сохраните презентацию.
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/AddNodes_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::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = smart->get_AllNodes()->AddNode(); | |
// Add Text | |
node->get_TextFrame()->set_Text(u"Test"); | |
// SharedPtr<ISmartArtNodeCollection> nodeCollection = System::DynamicCast_noexcept<ISmartArtNodeCollection>(node->get_ChildNodes()); ; | |
auto nodeCollection = node->get_ChildNodes() ; | |
// Adding new child node at end of parent node | |
SharedPtr<ISmartArtNode> chNode = nodeCollection->AddNode(); | |
// Add Text | |
chNode->get_TextFrame()->set_Text(u"Sample Text Added"); | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Добавить узел SmartArt в конкретной позиции
В следующем примере кода мы объяснили, как добавить дочерние узлы, относящиеся к соответствующим узлам фигуры SmartArt, в определенной позиции.
- Создайте экземпляр класса
Presentation
. - Получите ссылку на первый слайд, используя его индекс.
- Добавьте фигуру типа StackedList на доступный слайд.
- Получите доступ к первому узлу в добавленной фигуре SmartArt.
- Теперь добавьте дочерний узел для выбранного узла на позиции 2 и задайте его текст.
- Сохраните презентацию.
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/AddNodesSpecificPosition_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::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
// SharedPtr<ISmartArtNodeCollection> node0Collection = System::DynamicCast_noexcept<ISmartArtNodeCollection>(node0->get_ChildNodes()); ; | |
SharedPtr<ISmartArtNodeCollection> node0Collection = node0->get_ChildNodes() ; | |
// Adding new child node at position 2 in parent node | |
SharedPtr<ISmartArtNode> chNode = node0Collection->AddNodeByPosition(2); | |
// Add Text | |
chNode->get_TextFrame()->set_Text(u"Sample Text Added"); | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Получить доступ к узлу SmartArt
Следующий пример кода поможет получить доступ к узлам внутри фигуры SmartArt. Обратите внимание, что вы не можете изменить тип компоновки (LayoutType) 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"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Traverse through every shape inside first slide | |
//foreach(IShape shape in pres.Slides[0].Shapes) | |
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); | |
// Traverse through all nodes inside SmartArt | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(i)); | |
// Printing the SmartArt node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text() + u", Text = " + node->get_Level() + u", Position = " + node->get_Position()); | |
} | |
} | |
} |
Получить доступ к дочернему узлу SmartArt
Следующий пример кода поможет получить доступ к дочерним узлам, относящимся к соответствующим узлам фигуры SmartArt.
- Создайте экземпляр класса PresentationEx и загрузите презентацию с фигурой SmartArt.
- Получите ссылку на первый слайд, используя его индекс.
- Пройдите через каждую фигуру на первом слайде.
- Проверьте, является ли фигура типом SmartArt, и если это SmartArt, выполните приведение типа выбранной фигуры к SmartArtEx.
- Пройдите по всем узлам внутри фигуры 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); | |
// Traverse through all nodes inside SmartArt | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(i)); | |
// Traversing through the child nodes in SmartArt node at index i | |
for (int j = 0; j < node0->get_ChildNodes()->get_Count(); j++) | |
{ | |
// Accessing the child node in SmartArt node | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(node0->get_ChildNodes()->idx_get(j)); | |
// Printing the SmartArt child node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text()+u", Text = "+ node->get_Level()+u", Position = "+ node->get_Position()); | |
} | |
} | |
} | |
} |
Получить доступ к дочернему узлу SmartArt в конкретной позиции
В этом примере мы научимся получать доступ к дочерним узлам в определенной позиции, относящимся к соответствующим узлам фигуры SmartArt.
- Создайте экземпляр класса
Presentation
. - Получите ссылку на первый слайд, используя его индекс.
- Добавьте фигуру SmartArt типа StackedList.
- Получите доступ к добавленной фигуре SmartArt.
- Получите доступ к узлу с индексом 0 для полученной фигуры SmartArt.
- Теперь получите доступ к дочернему узлу на позиции 1 для полученного узла SmartArt, используя метод GetNodeByPosition().
- Получите доступ и отобразите такие данные, как позиция дочернего узла, уровень и текст.
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/AccessChildNodeSpecificPosition_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::StackedList); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node0 = smart->get_AllNodes()->idx_get(0); | |
//Accessing child node collection | |
auto nodeCollection =node0->get_ChildNodes(); | |
SharedPtr<SmartArtNode> foundChild; | |
int position = 1; | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = node0->get_ChildNodes()->idx_get(position); | |
// Printing the SmartArt child node parameters | |
System::Console::WriteLine(u"j = " + node->get_TextFrame()->get_Text() + u", Text = " + node->get_Level() + u", Position = " + node->get_Position()); | |
} | |
Удалить узел SmartArt
В этом примере мы научимся удалять узлы внутри фигуры SmartArt.
- Создайте экземпляр класса
Presentation
и загрузите презентацию с фигурой SmartArt. - Получите ссылку на первый слайд, используя его индекс.
- Пройдите через каждую фигуру на первом слайде.
- Проверьте, является ли фигура типом SmartArt, и если это SmartArt, выполните приведение типа выбранной фигуры к SmartArt.
- Проверьте, есть ли в SmartArt более 0 узлов.
- Выберите узел SmartArt, который необходимо удалить.
- Теперь удалите выбранный узел, используя метод RemoveNode(). Сохраните презентацию.
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/RemoveNode_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); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
// Removing the selected node | |
smart->get_AllNodes()->RemoveNode(node0); | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Удалить узел SmartArt в конкретной позиции
В этом примере мы научимся удалять узлы внутри фигуры SmartArt в конкретной позиции.
- Создайте экземпляр класса
Presentation
и загрузите презентацию с фигурой SmartArt. - Получите ссылку на первый слайд, используя его индекс.
- Пройдите через каждую фигуру на первом слайде.
- Проверьте, является ли фигура типом SmartArt, и если это SmartArt, выполните приведение типа выбранной фигуры к SmartArt.
- Выберите узел фигуры SmartArt с индексом 0.
- Теперь проверьте, есть ли у выбранного узла SmartArt более 2 дочерних узлов.
- Теперь удалите узел на позиции 1, используя метод RemoveNodeByPosition(). Сохраните презентацию.
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/RemoveSmartArtNodeByPosition_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); | |
if (smart->get_AllNodes()->get_Count() > 0) | |
{ | |
// Accessing SmartArt node at index 0 | |
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtNode> node0 = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtNode>(smart->get_AllNodes()->idx_get(0)); | |
if (node0->get_ChildNodes()->get_Count() >= 2) | |
{ | |
// Removing the child node at position 1 | |
node0->get_ChildNodes()->RemoveNode(1); | |
} | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Установить пользовательскую позицию для дочернего узла SmartArt
Теперь Aspose.Slides для .NET поддерживает установку свойств X и Y для SmartArtShape. Код ниже показывает, как задать пользовательскую позицию, размер и вращение для SmartArtShape; также обратите внимание, что добавление новых узлов приводит к перерасчёту позиций и размеров всех узлов.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
System::SharedPtr<ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(20, 20, 600, 500, Aspose::Slides::SmartArt::SmartArtLayoutType::OrganizationChart); | |
// Move SmartArt shape to new position | |
System::SharedPtr<ISmartArtNode> node = smart->get_AllNodes()->idx_get(1); | |
System::SharedPtr<ISmartArtShape> shape = node->get_Shapes()->idx_get(1); | |
shape->set_X((float)(shape->get_X() + (shape->get_Width() * 2))); | |
shape->set_Y((float)(shape->get_Y() - (shape->get_Height() / 2))); | |
// Change SmartArt shape's widths | |
node = smart->get_AllNodes()->idx_get(2); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Width(shape->get_Width() + (shape->get_Width() / 2)); | |
// Change SmartArt shape's height | |
node = smart->get_AllNodes()->idx_get(3); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Height(shape->get_Height() + (shape->get_Height() / 2)); | |
// Change SmartArt shape's rotation | |
node = smart->get_AllNodes()->idx_get(4); | |
shape = node->get_Shapes()->idx_get(1); | |
shape->set_Rotation(90); | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Проверить узел-ассистент
В следующем примере кода мы исследуем, как идентифицировать узлы-ассистенты в коллекции узлов SmartArt и изменять их.
- Создайте экземпляр класса PresentationEx и загрузите презентацию с фигурой SmartArt.
- Получите ссылку на второй слайд, используя его индекс.
- Пройдите через каждую фигуру на первом слайде.
- Проверьте, является ли фигура типом SmartArt, и если это SmartArt, выполните приведение типа выбранной фигуры к SmartArtEx.
- Пройдите по всем узлам внутри фигуры 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/AssistantNode.pptx"; | |
const String outPath = u"../out/ChangeAssitantNode_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); | |
for (int i = 0; i < smart->get_AllNodes()->get_Count(); i++) | |
{ | |
// Accessing SmartArt node at index i | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node = smart->get_AllNodes()->idx_get(i); | |
if (node->get_IsAssistant()) | |
{ | |
// Setting Assitant node to false and making it normal node | |
node->set_IsAssistant(false); | |
} | |
} | |
} | |
} | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |
Установить формат заливки узла
Aspose.Slides для C++ позволяет добавлять пользовательские фигуры SmartArt и устанавливать их форматы заливки. Эта статья объясняет, как создать и получить доступ к фигурам SmartArt и установить их формат заливки с использованием Aspose.Slides для C++.
Пожалуйста, выполните следующие шаги:
- Создайте экземпляр класса
Presentation
. - Получите ссылку на слайд, используя его индекс.
- Добавьте фигуру SmartArt, установив её тип компоновки.
- Установите FillFormat для узлов фигуры 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/FillFormat_SmartArt_ShapeNode_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::ClosedChevronProcess); | |
// Adding SmartArt node | |
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> NewNode = smart->get_AllNodes()->AddNode(); | |
//Adding text to added node | |
NewNode->get_TextFrame()->set_Text( u"Some text"); | |
// Save Presentation | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Сгенерировать миниатюру дочернего узла SmartArt
Разработчики могут сгенерировать миниатюру дочернего узла SmartArt, следуя приведённым ниже шагам:
- Создайте экземпляр класса
Presentation
, представляющий файл PPTX. - Добавьте 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 outPath = u"../out/CreateSmartArtChildNoteThumbnail_out.png"; | |
const String templatePath = u"../templates/HelloWorld.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Add SmartArt | |
SharedPtr<ISmartArt> smart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(10, 10, 400, 300, SmartArtLayoutType::BasicCycle); | |
// Obtain the reference of a node by using its Index | |
SharedPtr<ISmartArtNode> node = smart->get_Nodes()->idx_get(1); | |
// Get thumbnail | |
auto bitmap = node->get_Shapes()->idx_get(0)->GetThumbnail(); | |
// Save the image to disk in PNG format | |
bitmap->Save(outPath, System::Drawing::Imaging::ImageFormat::get_Png()); | |