从齿轮类型 SmartArt 形状中提取文本
Contents
[
Hide
]
可能的使用场景
Aspose.Cells 可以从齿轮类型智能艺术形状中提取文本。为此,您应该首先使用[形状.getResultOfSmartArt()](https://reference.aspose.com/cells/java/com.aspose.cells/shape#getResultOfSmartArt()) 方法。然后你应该使用[GroupShape.getGroupedShapes() 方法](https://reference.aspose.com/cells/java/com.aspose.cells/groupshape#getGroupedShapes()) 方法。最后,您可以在一个循环中一个一个地迭代所有单独的形状,并使用形状.文字财产。
从齿轮类型 SmartArt 形状中提取文本
下面的示例代码加载示例 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-Java | |
// Load sample Excel file containing gear type smart art shape. | |
Workbook wb = new Workbook(srcDir + "sampleExtractTextFromGearTypeSmartArtShape.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access first shape. | |
Shape sh = ws.getShapes().get(0); | |
// Get the result of gear type smart art shape in the form of group shape. | |
GroupShape gs = sh.getResultOfSmartArt(); | |
// Get the list of individual shapes consisting of group shape. | |
Shape[] shps = gs.getGroupedShapes(); | |
// Extract the text of gear type shapes and print them on console. | |
for (int i = 0; i < shps.length; i++) | |
{ | |
Shape s = shps[i]; | |
if (s.getType() == AutoShapeType.GEAR_9 || s.getType() == AutoShapeType.GEAR_6) | |
{ | |
System.out.println("Gear Type Shape Text: " + s.getText()); | |
} | |
}//for |
控制台输出
Gear Type Shape Text: Nice Gear Type Shape Text: Good Gear Type Shape Text: Excellent