Hücrenin Zengin Metin Kısımlarına Erişim ve Güncelleme

Zengin Metnin Kısımlarına Erişme ve Güncelleme

Aşağıdaki kod, kaynak excel dosyası kullanarak Cell.GetCharacters() ve Cell.SetCharacters() yöntemlerinin kullanımını göstermektedir. Kaynak excel dosyasında hücre A1’de zengin metin bulunmaktadır. 3 bölümü vardır ve her bölümün farklı bir fontu bulunmaktadır. Aşağıdaki kod parçacığı, bu bölümlere erişir ve ilk bölümü yeni bir font adı ile günceller. Son olarak, workbook’u çıktı excel dosyası olarak kaydeder. Açtığınızda, metnin ilk bölümünün fontunun “Arial” olarak değiştiğini göreceksiniz.

Hücrenin Zengin Metin Kısımlarına Erişme ve Güncelleme için C# kodu

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string inputPath = dataDir + "Sample.xlsx";
string outputPath = dataDir + "Output.out.xlsx";
Workbook workbook = new Workbook(inputPath);
Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet.Cells["A1"];
Console.WriteLine("Before updating the font settings....");
FontSetting[] fnts = cell.GetCharacters();
for (int i = 0; i < fnts.Length; i++)
{
Console.WriteLine(fnts[i].Font.Name);
}
// Modify the first FontSetting Font Name
fnts[0].Font.Name = "Arial";
// And update it using SetCharacters() method
cell.SetCharacters(fnts);
Console.WriteLine();
Console.WriteLine("After updating the font settings....");
fnts = cell.GetCharacters();
for (int i = 0; i < fnts.Length; i++)
{
Console.WriteLine(fnts[i].Font.Name);
}
// Save workbook
workbook.Save(outputPath);

Örnek kod tarafından oluşturulan konsol çıktısı

Yukarıdaki örnek kodun kaynak excel dosyası kullanılarak oluşturulan konsol çıktısı aşağıda verilmiştir.

Before updating the font settings....

Century

Courier New

Verdana

After updating the font settings....

Arial

Courier New

Verdana