قم بالوصول إلى أجزاء النص المنسق وتحديثها في Cell
Contents
[
Hide
]
Aspose.Cells يسمح لك بالتوصل وتحديث أجزاء النص المنسق للخانة. لهذا الغرض ، يمكنك استخدام أساليب Cell.getCharacters () و Cell.setCharacters (). ستعود هذه الطرق وتقبل مصفوفة كائنات FontSetting التي يمكنك استخدامها للوصول إلى الخصائص المختلفة للخط وتحديثها مثل اسم الخط ولون الخط والجرأة وما إلى ذلك.
قم بالوصول إلى أجزاء النص المنسق وتحديثها في Cell
يوضح الكود التالي استخدام الأسلوبين Cell.getCharacters () و Cell.setCharacters () باستخدامملف اكسل المصدر والتي يمكنك تنزيلها من الرابط المقدم. يحتوي ملف Excel المصدر على نص منسق في الخلية A1. يحتوي على 3 أجزاء ولكل جزء خط مختلف. سنصل إلى هذه الأجزاء ونحدث الجزء الأول باسم خط جديد. أخيرًا ، يحفظ المصنف باسمملف اكسل الناتج . عندما تفتحه ، ستجد أن خط الجزء الأول من النص قد تغير إلى**“اريال”**.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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