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ını kullanarak Cell.getCharacters() ve Cell.setCharacters() metodlarının kullanımını gösterir. Kaynak excel dosyasında A1 hücresinde zengin metin bulunmaktadır. 3 kısmı vardır ve her bir kısmı farklı bir yazı tipine sahiptir. Bu kısımlara erişeceğiz ve ilk kısmı yeni yazı tipi ile güncelleyeceğiz. Son olarak, çalışma kitabını çıktı excel dosyası olarak kaydeder. Bu dosyayı açtığınızda, metnin ilk kısmının yazı tipinin “Arial” olarak değiştiğini göreceksiniz.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessAndUpdatePortions.class); | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cell cell = worksheet.getCells().get("A1"); | |
System.out.println("Before updating the font settings...."); | |
FontSetting[] fnts = cell.getCharacters(); | |
for (int i = 0; i < fnts.length; i++) { | |
System.out.println(fnts[i].getFont().getName()); | |
} | |
// Modify the first FontSetting Font Name | |
fnts[0].getFont().setName("Arial"); | |
// And update it using SetCharacters() method | |
cell.setCharacters(fnts); | |
System.out.println(); | |
System.out.println("After updating the font settings...."); | |
fnts = cell.getCharacters(); | |
for (int i = 0; i < fnts.length; i++) { | |
System.out.println(fnts[i].getFont().getName()); | |
} | |
// Save workbook | |
workbook.save(dataDir + "output.xlsx"); |
Konsol Çıktısı
Yukarıdaki örnek kodun konsol çıktısı için kaynak excel dosyası kullanılarak konsol çıktısı verilmiştir.
Before updating the font settings....
Century
Courier New
Verdana
After updating the font settings....
Arial
Courier New
Verdana