إعدادات الخط
تكوين إعدادات الخط
Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىأوراق عمل مجموعة تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCells مجموعة. كل عنصر فيCells تمثل المجموعة كائنًا منCellصف دراسي.
يوفر Aspose.Cells ملفCell صف دراسي'GetStyle وSetStyle الأساليب المستخدمة للحصول على نمط تنسيق الخلية وتعيينه. الأسلوبتوفر فئة خصائص لتكوين إعدادات الخط.
تعيين اسم الخط
يمكن للمطورين تطبيق أي خط على نص داخل خلية باستخدامأسلوب الخط أشياءاسمخاصية.
// 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); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font name to "Times New Roman" | |
style.Font.Name = "Times New Roman"; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
تعيين نمط الخط إلى غامق
يمكن للمطورين جعل النص غامقًا عن طريق تعيينأسلوب الخط أشياءIsBold ملكية لحقيقي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font weight to bold | |
style.Font.IsBold = true; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); | |
ضبط حجم الخط
اضبط حجم الخط بامتدادأسلوب الخطأشياءبحجمخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font size to 14 | |
style.Font.Size = 14; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); | |
ضبط لون الخط
استخدم الأسلوب الخط أشياءاللونخاصية لتعيين لون الخط. حدد أي لون من تعداد اللون (جزء من إطار عمل .NET) وقم بتعيينه إلىاللونخاصية.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font color to blue | |
style.Font.Color = Color.Blue; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); | |
تعيين نوع تسطير الخط
استخدم الأسلوب الخطأشياءتسطيرخاصية لتسطير النص. يوفر Aspose.Cells أنواعًا مختلفة من تسطير الخط المعرفة مسبقًا في تنسيقFontUnderlineType تعداد.
أنواع تسطير الخط | وصف |
---|---|
محاسبة | تسطير محاسبة واحد |
مزدوج | تسطير مزدوج |
حساب مزدوج | تسطير مزدوج المحاسبة |
لا أحد | بدون تسطير |
غير مرتبطة | تسطير واحد |
// 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); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font to be underlined | |
style.Font.Underline = FontUnderlineType.Single; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "out.xlsx"); |
إعداد تأثير الشطب
تطبيق الشطب عن طريق ضبطأسلوب الخط أشياءIsStrikeoutملكية لحقيقي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the strike out effect on the font | |
style.Font.IsStrikeout = true; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "out.xlsx"); | |
إعداد تأثير منخفض
تطبيق منخفض عن طريق تعيينأسلوب الخطأشياءIsSubScript ملكية لحقيقي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting subscript effect | |
style.Font.IsSubscript = true; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "out.xlsx"); | |
إعداد تأثير الكتابة المرتفعة على الخط
يمكن للمطورين تطبيق تأثير الكتابة المرتفعة على الخط عن طريق تعيين ملفهو مرتفع ممتلكاتأسلوب الخط يعترض علىحقيقي.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting superscript effect | |
style.Font.IsSuperscript = true; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "out.xlsx"); |