管理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文件。
在以下示例中,我们在两个形状之间添加了连线。
获取或设置组织结构图类型
方法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 for C++提供了一个简单的API,以便以简单的方式创建和图片组织结构图。要在幻灯片上创建图表:
- 创建一个Presentation类的实例。
- 通过索引获取幻灯片的引用。
- 添加一个带有默认数据和所需类型(ChartType.PictureOrganizationChart)的图表。
- 将修改后的演示文稿写入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);