用C++提取Gear类型SmartArt形状中的文本

可能的使用场景

Aspose.Cells for C++可以提取Gear类型SmartArt形状中的文本。请按以下步骤操作:

  1. 使用Shape::GetResultOfSmartArt()方法将SmartArt形状转换为组形状。
  2. 使用GroupShape::GetGroupedShapes()方法获取组成组形状的所有单个形状。
  3. 遍历每个单个形状并使用GetText()方法提取文本。

从齿轮型智能图形中提取文本

以下示例代码加载包含Gear类型SmartArt形状的示例Excel文件,并从其单个形状中提取文本。结果请参见下面的控制台输出。

示例代码

#include <iostream>
#include "Aspose.Cells.h"

using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;

int main()
{
    Aspose::Cells::Startup();

    // Load sample Excel file containing gear type smart art shape
    U16String inputFile(u"sampleExtractTextFromGearTypeSmartArtShape.xlsx");
    Workbook wb(inputFile);

    // Access first worksheet
    Worksheet ws = wb.GetWorksheets().Get(0);

    // Access first shape
    Shape sh = ws.GetShapes().Get(0);

    // Get SmartArt result as group shape
    GroupShape gs = sh.GetResultOfSmartArt();

    // Get grouped shapes collection
    Vector<Shape> shps = gs.GetGroupedShapes();

    // Iterate through shapes and check gear types
    for (int i = 0; i < shps.GetLength(); i++)
    {
        Shape s = shps[i];
        AutoShapeType shapeType = s.GetType();

        if (shapeType == AutoShapeType::Gear9 || shapeType == AutoShapeType::Gear6)
        {
            std::cout << "Gear Type Shape Text: " << s.GetText().ToUtf8() << std::endl;
        }
    }

    Aspose::Cells::Cleanup();
    return 0;
}

控制台输出

Gear Type Shape Text: Nice
Gear Type Shape Text: Good
Gear Type Shape Text: Excellent