إعدادات الحدود

إضافة حدود إلى الخلايا

يسمح Microsoft Excel للمستخدمين بتنسيق الخلايا عن طريق إضافة الحدود. نوع الحدود يعتمد على مكان إضافته. على سبيل المثال، يعد الحد العلوي هو الحد الذي يتم إضافته إلى الموضع العلوي للخلية. يمكن للمستخدمين أيضاً تعديل نمط الخطوط ولونها.

مع Aspose.Cells for Python via .NET، يمكن للمطورين إضافة حدود وتخصيص مظهرها بنفس الطريقة المرنة مثلما في Microsoft Excel.

إضافة حدود إلى الخلايا

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

يوفر Aspose.Cells for Python via .NET الطريقة get_style في فئة Cell. تُستخدم طريقة set_style لضبط نمط تنسيق الخلية. توفر فئة Style خصائص لإضافة حدود إلى الخلايا.

إضافة حدود إلى خلية

يمكن للمطورين إضافة حدود إلى خلية باستخدام مجموعة borders الخاصة بكائن Style. يتم تمرير نوع الحدود كفهرس إلى المجموعة borders. تم تحديد جميع أنواع الحدود مسبقًا في تعداد BorderType.

تعداد الحدود

أنواع الحدود الوصف
BOTTOM_BORDER خط حدود سفلي
DIAGONAL_DOWN خط قطري من أعلى اليسار إلى أسفل اليمين
DIAGONAL_UP خط قطري من أسفل اليسار إلى أعلى اليمين
LEFT_BORDER خط حدود أيسر
RIGHT_BORDER خط حدود أيمن
TOP_BORDER خط حدود علوي

The borders collection stores all borders. Each border in the Borders collection is represented by a Border object which provides two properties, color and line_style to set a border’s line color and style respectively.

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

يتم ضبط نمط الخط للحدود عن طريق اختيار نمط خط من تعداد CellBorderType.

تعداد CellBorderType

أنماط الخطوط الوصف
DASH_DOT خط منقط ناعم
DASH_DOT_DOT خط منقط منقّط ناعم مع نقطتين
DASHED خط منقّط
DOTTED خط منقط
DOUBLE خط مزدوج
HAIR خط شعر رقيقة جدا
MEDIUM_DASH_DOT خط متوسط منقط ناعم
MEDIUM_DASH_DOT_DOT خط متوسط منقط منقط ناعم مع نقطتين
MEDIUM_DASHED خط متوسط منقّط
NONE لا يوجد خط
MEDIUM خط متوسط
SLANTED_DASH_DOT خط منقّط مائل متوسط الخط
THICK خط سميك
THIN خط رفيع
حدد أحد أنماط الخط ثم اسنده لخاصية line_style للكائن Border.
from aspose.cells import BorderType, CellBorderType, Workbook
from aspose.pydrawing import Color
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()
# Obtaining the reference of the first (default) worksheet by passing its sheet index
worksheet = workbook.worksheets[0]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Visit Aspose!")
# Create a style object
style = cell.get_style()
# Setting the line style of the top border
style.borders.get(BorderType.TOP_BORDER).line_style = CellBorderType.THICK
# Setting the color of the top border
style.borders.get(BorderType.TOP_BORDER).color = Color.black
# Setting the line style of the bottom border
style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.THICK
# Setting the color of the bottom border
style.borders.get(BorderType.BOTTOM_BORDER).color = Color.black
# Setting the line style of the left border
style.borders.get(BorderType.LEFT_BORDER).line_style = CellBorderType.THICK
# Setting the color of the left border
style.borders.get(BorderType.LEFT_BORDER).color = Color.black
# Setting the line style of the right border
style.borders.get(BorderType.RIGHT_BORDER).line_style = CellBorderType.THICK
# Setting the color of the right border
style.borders.get(BorderType.RIGHT_BORDER).color = Color.black
# Apply the border styles to the cell
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

إضافة حدود لمجموعة من الخلايا

من الممكن أيضًا إضافة حدود لمجموعة من الخلايا بدلاً من خلية واحدة فقط. للقيام بذلك، أنشئ أولاً مجموعة من الخلايا من خلال استدعاء طريقة create_range لمجموعة Cells. تأخذ الطريقة السمات التالية:

  • الصف الأول، الصف الأول من المجموعة.
  • العمود الأول، يمثل العمود الأول من المجموعة.
  • عدد الصفوف، عدد الصفوف في المجموعة.
  • عدد الأعمدة، عدد الأعمدة في المجموعة.

تعيد الطريقة Range كائن create_range، الذي يحتوي على مجموعة الخلايا المحددة. يوفر الكائن Range طريقة set_outline_border التي تأخذ السمات التالية لإضافة حد لمجموعة الخلايا:

  • نوع الحد، نوع الحد، المحدد من تعداد BorderType.
  • نمط الخط، نمط الخط الحدودي، المحدد من التعداد CellBorderType.
  • اللون، لون الخط، المحدد من تعداد الألوان.
from aspose.cells import BorderType, CellBorderType, Workbook
from aspose.pydrawing import Color
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()
# Obtaining the reference of the first (default) worksheet by passing its sheet index
worksheet = workbook.worksheets[0]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello World From Aspose")
# Creating a range of cells starting from "A1" cell to 3rd column in a row
range = worksheet.cells.create_range(0, 0, 1, 3)
# Adding a thick top border with blue line
range.set_outline_border(BorderType.TOP_BORDER, CellBorderType.THICK, Color.blue)
# Adding a thick bottom border with blue line
range.set_outline_border(BorderType.BOTTOM_BORDER, CellBorderType.THICK, Color.blue)
# Adding a thick left border with blue line
range.set_outline_border(BorderType.LEFT_BORDER, CellBorderType.THICK, Color.blue)
# Adding a thick right border with blue line
range.set_outline_border(BorderType.RIGHT_BORDER, CellBorderType.THICK, Color.blue)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")