Управление SmartArt

Получить текст из SmartArt

Теперь свойство TextFrame было добавлено в интерфейс ISmartArtShape и класс SmartArtShape соответственно. Это свойство позволяет вам получить весь текст из 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));
int iNodeShapeCount = node->get_Shapes()->get_Count();
for(int j=0; j < iNodeShapeCount;j++)
{
System::SharedPtr<Aspose::Slides::SmartArt::SmartArtShape> nodeShape=System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtShape>(node->get_Shapes()->idx_get(j));
//auto nodeShape = System::DynamicCast_noexcept<Aspose::Slides::SmartArt::SmartArtShape>(node->get_Shapes()->idx_get(j));
if (nodeShape->get_TextFrame() != NULL)
{
// Printing the SmartArt nodeShape parameters
System::Console::WriteLine(u"NodeShape Text is: {0}", nodeShape->get_TextFrame()->get_Text());
}
}
}
}
}

Изменить тип макета любого SmartArt

Чтобы изменить тип макета SmartArt, выполните следующие шаги:

  • Создайте экземпляр класса Presentation.
  • Получите ссылку на слайд, используя его индекс.
  • Добавьте SmartArt BasicBlockList.
  • Измените LayoutType на BasicProcess.
  • Сохраните презентацию в файл 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/ChangeSmartArtLayout_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);
// Change LayoutType to BasicProcess
smart->set_Layout(SmartArtLayoutType::BasicProcess);
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Проверить скрытое свойство SmartArt

Обратите внимание, что метод com.aspose.slides.ISmartArtNode.isHidden() возвращает true, если этот узел является скрытым узлом в модели данных. Чтобы проверить скрытое свойство любого узла SmartArt, выполните следующие шаги:

  • Создайте экземпляр класса Presentation.
  • Добавьте SmartArt RadialCycle.
  • Добавьте узел на SmartArt.
  • Проверьте свойство isHidden.
  • Запишите презентацию в файл 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/CheckSmartArtHiddenProperty_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::RadialCycle);
// Adding SmartArt node
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> NewNode = smart->get_AllNodes()->AddNode();
// Check isHidden property
bool hidden = NewNode->get_IsHidden(); // Returns true
if (hidden)
{
// Do some actions or notifications
}
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Получить или установить тип организационной диаграммы

Методы com.aspose.slides.ISmartArtNode.getOrganizationChartLayout(), setOrganizationChartLayout(int) позволяют получить или установить тип организационной диаграммы, связанный с текущим узлом. Чтобы получить или установить тип организационной диаграммы, выполните следующие шаги:

  • Создайте экземпляр класса 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 templatePath = u"../templates/SmartArt.pptx";
const String outPath = u"../out/OrganizeChartLayoutType_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::OrganizationChart);
// Accessing SmartArt node at index 0
System::SharedPtr<Aspose::Slides::SmartArt::ISmartArtNode> node0 = smart->get_AllNodes()->idx_get(0);
// Get or Set the organization chart type
node0->set_OrganizationChartLayout(OrganizationChartLayoutType::LeftHanging);
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Получить или установить состояние SmartArt

Некоторые диаграммы SmartArt не поддерживают реверсирование, например, вертикальный список маркеров, вертикальный процесс, нисходящий процесс, воронка, шестерня, баланс, круговые отношения, кластер из шестиугольников, обратный список, сложенный Венн. Чтобы изменить ориентацию SmartArt, выполните следующие шаги:

  • Создайте экземпляр класса Presentation.
  • Добавьте SmartArt на слайд.
  • Получите или установите состояние диаграммы 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/ChangeSmartArtLayout_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);
// Change LayoutType to BasicProcess
smart->set_Layout(SmartArtLayoutType::BasicProcess);
// Save Presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Создать организационную диаграмму с картинкой

Aspose.Slides для C++ предоставляет простой API для создания диаграмм и диаграмм PictureOrganization простым способом. Чтобы создать диаграмму на слайде:

  1. Создайте экземпляр класса Presentation.
  2. Получите ссылку на слайд по его индексу.
  3. Добавьте диаграмму с данными по умолчанию с желаемым типом (ChartType.PictureOrganizationChart).
  4. Запишите измененную презентацию в файл PPTX.

Следующий код используется для создания диаграммы.

auto pres = System::MakeObject<Presentation>(u"test.pptx");
auto smartArt = pres->get_Slides()->idx_get(0)->get_Shapes()->AddSmartArt(0.0f, 0.0f, 400.0f, 400.0f, SmartArtLayoutType::PictureOrganizationChart);
pres->Save(u"OrganizationChart.pptx", SaveFormat::Pptx);