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