الوصول إلى وتحديث أجزاء النص الغني للخلية باستخدام ++C

الوصول إلى وتحديث أجزاء النص الغني للخلية

توضح الشفرة التالية استخدام طرق Cell->GetCharacters() و Cell->SetCharacters() باستخدام ملف إكسل المصدر (ملف إكسل). يحتوي ملف إكسل المصدر على نص غني في الخلية A1 بثلاث أجزاء، كل جزء بتنسيق مختلف. تصل هذه الأجزاء وتحدث خط التنسيق الخاص بالجزء الأول إلى “Arial”. يتم حفظ المصنف المعدل كملف إكسل الناتج (ملف إكسل المخرجات).

كود ++C للوصول إلى أجزاء النص الغني وتحديثها

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

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

    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
    U16String outDir(u"..\\Data\\02_OutputDirectory\\");

    U16String inputPath = srcDir + u"Sample.xlsx";
    U16String outputPath = outDir + u"Output.out.xlsx";

    Workbook workbook(inputPath);

    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    Cell cell = worksheet.GetCells().Get(U16String(u"A1"));

    std::cout << "Before updating the font settings...." << std::endl;

    Vector<FontSetting> fnts = cell.GetCharacters();

    for (int i = 0; i < fnts.GetLength(); ++i)
    {
        FontSetting& fs = fnts[i];
        std::cout << fs.GetFont().GetName().ToUtf8() << std::endl;
    }

    if (fnts.GetLength() > 0)
    {
        FontSetting& fs = fnts[0];
        fs.GetFont().SetName(u"Arial");
        cell.SetCharacters(fnts);
    }

    std::cout << std::endl << "After updating the font settings...." << std::endl;

    fnts = cell.GetCharacters();

    for (int i = 0; i < fnts.GetLength(); ++i)
    {
        FontSetting& fs = fnts[i];
        std::cout << fs.GetFont().GetName().ToUtf8() << std::endl;
    }

    workbook.Save(outputPath);

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

المخرجات في وحدة الطرفية التي تم إنشاؤها بواسطة الكود النموذجي

إليك إخراج وحدة التحكم عند استخدام ملف إكسل المصدر:

Before updating the font settings....
Century
Courier New
Verdana

After updating the font settings....
Arial
Courier New
Verdana