从齿轮型智能图形中提取文本
Contents
[
Hide
]
可能的使用场景
Aspose.Cells可以从齿轮型智能图形中提取文本。为了实现这一点,您应首先使用Shape.GetResultOfSmartArt()方法将智能图形转为组合形状。然后使用GroupShape.GetGroupedShapes()方法获取组合形状中形成的所有单个形状的数组。最后,您可以循环逐个迭代所有单个形状,并使用Shape.Text属性提取其文本。
从齿轮型智能图形中提取文本
以下示例代码加载包含齿轮型智能图形的sample Excel文件。然后按上述步骤从其各个形状中提取文本。请参阅下面提供的代码的控制台输出以供参考。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing gear type smart art shape. | |
Workbook wb = new Workbook("sampleExtractTextFromGearTypeSmartArtShape.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first shape. | |
Aspose.Cells.Drawing.Shape sh = ws.Shapes[0]; | |
// Get the result of gear type smart art shape in the form of group shape. | |
Aspose.Cells.Drawing.GroupShape gs = sh.GetResultOfSmartArt(); | |
// Get the list of individual shapes consisting of group shape. | |
Aspose.Cells.Drawing.Shape[] shps = gs.GetGroupedShapes(); | |
// Extract the text of gear type shapes and print them on console. | |
for (int i = 0; i < shps.Length; i++) | |
{ | |
Aspose.Cells.Drawing.Shape s = shps[i]; | |
if (s.Type == Aspose.Cells.Drawing.AutoShapeType.Gear9 || s.Type == Aspose.Cells.Drawing.AutoShapeType.Gear6) | |
{ | |
Console.WriteLine("Gear Type Shape Text: " + s.Text); | |
} | |
}//for |
控制台输出
Gear Type Shape Text: Nice
Gear Type Shape Text: Good
Gear Type Shape Text: Excellent