إعدادات الخط

تكوين إعدادات الخط

توفر Aspose.Cells for Python via .NET فئة Workbook تمثل ملف إكسل من مايكروسوفت. تحتوي الفئة Workbook على مجموعة worksheets التي تسمح بالوصول إلى كل ورقة عمل في ملف إكسل. يتم تمثيل ورقة العمل بواسطة فئة Worksheet. توفر الفئة Worksheet مجموعة cells. كل عنصر في المجموعة cells يمثل كائنًا من فئة Cell.

توفر Aspose.Cells فئة Cell وطرق get_style و set_style تُستخدم للحصول على وتعيين نمط تنسيق الخلية. توفر الفئة Style خصائص لتكوين إعدادات الخط.

تعيين اسم الخط

يمكن للمطورين تطبيق أي خط على النص داخل خلية باستخدام خاصية name لكائن Style.font.

from aspose.cells import SaveFormat, Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the font name to "Times New Roman"
style.font.name = "Times New Roman"
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

تعيين نمط الخط إلى عريض

يمكن للمطورين جعل النص عريضًا عن طريق ضبط خاصية is_bold من كائن Style.font على صحيح.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the font weight to bold
style.font.is_bold = True
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save("out.xlsx")

تعيين حجم الخط

قم بتعيين حجم الخط باستخدام خاصية size لكائن Style.font.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the font size to 14
style.font.size = 14
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save("out.xlsx")

تعيين لون الخط

استخدم خاصية color لكائن Style.font لتعيين لون الخط. اختر أي لون من تعداد الألوان (جزء من إطار العمل .NET) وقم بتعيينه إلى الخاصية color.

from aspose.cells import Workbook
from aspose.pydrawing import Color
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the font color to blue
style.font.color = Color.blue
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save("out.xlsx")

تعيين نوع تسطير الخط

استخدم الخاصية underline في كائن Style.font لتحتية النص. تقدم مكتبة Aspose.Cells لبايثون via .NET أنواع خط تحتية معرف مسبقاً في تعداد FontUnderlineType.

أنواع تسطير الخط الوصف
المحاسبة تحتية محاسبة مفردة
مزدوج تحتية مزدوجة
محاسبة_مزدوجة تحتية محاسبة مزدوجة
بلا لا يوجد خط تحت
فردي خط تحت واحد
from aspose.cells import FontUnderlineType, Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the font to be underlined
style.font.underline = FontUnderlineType.SINGLE
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "out.xlsx")

ضبط تأثير شطب

تطبيق تأثير الشطب عن طريق ضبط خاصية is_strikeout لكائن Style.font إلى true.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting the strike out effect on the font
style.font.is_strikeout = True
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "out.xlsx")

ضبط تأثير الرمز الفرعي

تطبيق الرمز الفرعي عن طريق ضبط خاصية is_subscript لكائن Style.font إلى true.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting subscript effect
style.font.is_subscript = True
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "out.xlsx")

ضبط تأثير الرمز العلوي على الخط

يمكن للمطورين تطبيق تأثير الرمز العلوي على الخط عن طريق ضبط خاصية is_superscript لكائن Style.font إلى true.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Obtaining the style of the cell
style = cell.get_style()
# Setting superscript effect
style.font.is_superscript = True
# Applying the style to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "out.xlsx")

مواضيع متقدمة