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ı üzerinde Cell.get_characters() ve Cell.set_characters() yöntemlerinin kullanımını gösterir. Kaynak excel dosyasında bir hücrede zengin metin bulunmaktadır. 3 bölümü bulunmakta ve her bir bölüm farklı bir yazı tipine sahiptir. Aşağıdaki kod parçası, bu bölümlere erişir ve ilk bölümü yeni bir yazı tipiyle günceller. Son olarak, çalışma kitabını çıktı excel dosyası olarak kaydeder. Açtığınızda, metnin ilk bölümünün yazı tipinin “Arial” olarak değişmiş olduğunu göreceksiniz.
Hücrenin Zengin Metin Kısımlarına Erişme ve Güncelleme için C# kodu
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
inputPath = dataDir + "Sample.xlsx" | |
outputPath = dataDir + "Output.out.xlsx" | |
workbook = Workbook(inputPath) | |
worksheet = workbook.worksheets[0] | |
cell = worksheet.cells.get("A1") | |
print("Before updating the font settings....") | |
fnts = cell.get_characters() | |
for i in range(len(fnts)): | |
print(fnts[i].font.name) | |
# Modify the first FontSetting Font Name | |
fnts[0].font.name = "Arial" | |
# And update it using SetCharacters() method | |
cell.set_characters(fnts) | |
print() | |
print("After updating the font settings....") | |
fnts = cell.get_characters() | |
for i in range(len(fnts)): | |
print(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