Hücre Değeri Metninin Genişliğini C++ ile alın

Hücre Değeri Metnin Genişliğini Alma

Bazen geliştiriciler, veriyi düzenlemek için hücrenin değerinin genişliğini hesaplamaları gerekebilir. Aspose.Cells, geliştiricilerin hücrenin değerinin metin genişliğini almalarına olanak tanıyan CellsHelper::GetTextWidth metodunu sağlar. Aşağıdaki örnek kod, CellsHelper::GetTextWidth kullanarak hücrenin metin genişliğine nasıl erişileceğini gösterir.

Aşağıdaki kod parçasında kullanılan Kaynak dosyası, referansınız için ekte bulunmaktadır.

Kaynak Dosya

Örnek Kod

#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

    // Directory path for source files
    U16String sourceDir(u"..\\Data\\01_SourceDirectory\\");

    // Create workbook from the specified Excel file
    Workbook workbook(sourceDir + u"GetTextWidthSample.xlsx");

    // Calculate the text width for the string value of cell A1
    double textWidth = CellsHelper::GetTextWidth(workbook.GetWorksheets().Get(0).GetCells().Get(u"A1").GetStringValue(), workbook.GetDefaultStyle().GetFont(), 1);

    // Output the text width
    std::wcout << u"Text width: " << textWidth << std::endl;

    Aspose::Cells::Cleanup();
}