الوصول وتحديث أجزاء النص الغني للخلية
الوصول إلى وتحديث أجزاء النص الغني للخلية
يوضح الكود التالي استخدام الطرق Cell.getCharacters() و Cell.setCharacters() باستخدام ملف الإكسل المصدر الذي يمكنك تنزيله من الرابط المقدم. يحتوي ملف الإكسل المصدر على نص غني في الخلية A1. يحتوي على 3 أجزاء وكل جزء له خط مختلف. سنوصل إلى هذه الأجزاء ونحدث الجزء الأول باسم خط جديد. في النهاية، يقوم بحفظ دفتر العمل باسم ملف الإكسل الناتج. عند فتحه، ستجد أن خط الجزء الأول من النص قد تغير إلى “Arial”.
// 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"); |
مخرجات الوحدة
فيما يلي مخرجات الكونسول للكود العينة أعلاه باستخدام ملف الإكسل المصدر.
Before updating the font settings....
Century
Courier New
Verdana
After updating the font settings....
Arial
Courier New
Verdana