C++を使用してチャートのデータラベルシェイプを調整し、テキストにフィットさせる

Microsoft Excelのインタフェース上で、チャートのデータラベルを選択して、フォーマットデータラベルメニューを右クリックします。サイズとプロパティタブで、配置を展開して、テキストに合わせて形状を変更オプションを含む関連プロパティを表示します。

このオプションは、チャート上の任意のデータラベルを選択し、右クリックしてデータラベルの書式設定メニューからアクセスできます。サイズとプロパティタブの下にある整列を展開すると、必要な関連プロパティが表示されます、その中にテキストに合わせて形状をリサイズオプションがあります。

Aspose.Cells for C++を使用してチャートのデータラベルシェイプをリサイズする方法

Excelの機能に似せて、データラベルの形状をテキストにフィットさせるために、Aspose.Cells APIはブール型のDataLabels.IsResizeShapeToFitTextプロパティを公開しています。以下のコード例は、そのDataLabels.IsResizeShapeToFitTextプロパティの簡単な使用例を示しています。

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

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

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Path of input excel file
    U16String inputFilePath = srcDir + u"source.xlsx";

    // Create an instance of Workbook containing the Chart
    Workbook book(inputFilePath);

    // Access the Worksheet that contains the Chart
    Worksheet sheet = book.GetWorksheets().Get(0);

    // Iterate through each Chart in the Worksheet
    for (int32_t i = 0; i < sheet.GetCharts().GetCount(); i++)
    {
        Chart chart = sheet.GetCharts().Get(i);

        // Iterate through each NSeries in the Chart
        for (int32_t index = 0; index < chart.GetNSeries().GetCount(); index++)
        {
            // Access the DataLabels of indexed NSeries
            DataLabels labels = chart.GetNSeries().Get(index).GetDataLabels();

            // Set ResizeShapeToFitText property to true
            labels.SetIsResizeShapeToFitText(true);
        }

        // Calculate Chart
        chart.Calculate();
    }

    // Save the result
    U16String outputFilePath = srcDir + u"output_out.xlsx";
    book.Save(outputFilePath);

    std::cout << "Chart calculations and modifications completed successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}