Style
Properties Style الصف وفئاته المرافقة تتحكم في جميع التنسيقات البصرية والحماية المطبقة على الخلايا في aspose-cells-foss. A Style يتم الحصول على الكائن من خلية عبر cell.get_style() ويتم تطبيقه مرة أخرى باستخدام cell.apply_style(style).
Properties: aspose.cells_foss
from aspose.cells_foss import Style, Font, Fill, Border, Borders, Alignment, NumberFormat, ProtectionProperties
Properties
Style()ينشئ افتراضيًا Style بدون أي تنسيق صريح مطبق.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
font | Font | Properties | إعدادات الخط (الاسم، الحجم، اللون، غامق، مائل، تحت الخط، شطب). |
fill | Fill | Properties | إعدادات تعبئة/خلفية الخلية (النمط، لون المقدمة، لون الخلفية). |
borders | Borders | Properties | جميع إعدادات الحدود للخلية (أعلى، أسفل، يسار، يمين، قطري). |
alignment | Alignment | Properties | إعدادات محاذاة النص (أفقي، عمودي، التفاف، مسافة بادئة، دوران). |
number_format | str | قراءة/كتابة | سلسلة رمز تنسيق الرقم النشط (مثلاً،., "#,##0.00"). |
protection | Protection | Properties | إعدادات حماية الخلية (مقفل، إخفاء الصيغة). |
Properties
نسخ
style.copy() -> Styleيعيد نسخة عميقة من كائن النمط هذا.
set_fill_color
style.set_fill_color(color: str)يضبط لون خلفية التعبئة الصلبة. color هي سلسلة سداسية RRGGBB (مثلاً،., "FFFF00" للون الأصفر).
set_fill_pattern
style.set_fill_pattern(pattern_type: str, fg_color: str = 'FFFFFFFF', bg_color: str = 'FFFFFFFF')يضبط تعبئة بنمط. pattern_type القيم تشمل 'solid', 'darkGray', 'mediumGray', 'lightGray', 'gray125', 'gray0625', 'darkHorizontal', 'darkVertical', 'darkDown', 'darkUp', 'darkGrid', 'darkTrellis', 'lightHorizontal', 'lightVertical', 'lightDown', 'lightUp', 'lightGrid', 'lightTrellis'.
set_no_fill
style.set_no_fill()يمسح أي تعبئة، ويضبط خلفية الخلية لتكون شفافة (بدون تعبئة).
set_border_color
style.set_border_color(side: str, color: str)يضبط لون جانب واحد من الحدود. side يجب أن يكون أحد 'top', 'bottom', 'left', 'right', 'diagonal'. color هي سلسلة سداسية RRGGBB.
set_border_style
style.set_border_style(side: str, style: str)يضبط نمط الخط لجانب الحد. style القيم: 'none', 'thin', 'medium', 'thick', 'dashed', 'dotted', 'double'.
set_border_weight
style.set_border_weight(side: str, weight: int)يضبط وزن الخط (السُمك) لجانب الحد كعدد صحيح.
set_border
style.set_border(side: str, line_style='none', color='FF000000', weight=1)طريقة مريحة تقوم بضبط نمط الخط واللون والوزن لجانب حد واحد في استدعاء واحد.
set_diagonal_border
style.set_diagonal_border(line_style='none', color='FF000000', weight=1, up=False, down=False)يضبط الحد القطري. مرّر up=True لخط قطري صاعد،, down=True لخط قطري هابط، أو كليهما لرسم صليب.
set_horizontal_alignment
style.set_horizontal_alignment(alignment: str)يضبط محاذاة النص أفقياً. القيم: 'general', 'left', 'center', 'right', 'fill', 'justify', 'centerContinuous', 'distributed'.
set_vertical_alignment
style.set_vertical_alignment(alignment: str)يضبط محاذاة النص عمودياً. القيم: 'top', 'center', 'bottom', 'justify', 'distributed'.
set_text_wrap
style.set_text_wrap(wrap=True)يفعل أو يعطل التفاف النص داخل الخلية.
set_shrink_to_fit
style.set_shrink_to_fit(shrink=True)يفعل أو يعطل تصغير النص ليتناسب. عند التفعيل، يتم تقليل حجم النص ليتناسب مع عرض الخلية.
set_indent
style.set_indent(indent: int)يضبط مستوى الإزاحة (0–15).
set_text_rotation
style.set_text_rotation(rotation: int)يضبط دوران النص بالدرجات. القيم الصالحة هي 0–180 (عكس اتجاه عقارب الساعة من 0°) أو 255 (نص عمودي مكدس من الأعلى إلى الأسفل).
set_reading_order
style.set_reading_order(order: int)يضبط ترتيب القراءة. 0 = يعتمد على السياق،, 1 = من اليسار إلى اليمين،, 2 = من اليمين إلى اليسار.
set_number_format
style.set_number_format(format_code: str)= يطبق سلسلة تنسيق رقم مخصصة (مثالاً،., "DD/MM/YYYY", "#,##0.00 [$€-407]").
set_builtin_number_format
style.set_builtin_number_format(format_id: int)= يطبق أحد تنسيقات الأرقام المدمجة في Excel باستخدام معرفه الرقمي (مثالاً،., 9 = "0%", 14 = "m/d/yy").
set_locked
style.set_locked(locked=True)يُعلِّم الخلية كمقفلة. لا يمكن تعديل الخلايا المقفلة عندما يكون حماية الورقة مفعلة.
set_formula_hidden
style.set_formula_hidden(hidden=True)يخفي الصيغ من شريط الصيغ عندما تكون حماية الورقة مفعلة.
Properties
Properties
Font(name='Calibri', size=11, color='FF000000', bold=False, italic=False, underline=False, strikethrough=False)Properties
| Properties | Properties | Properties |
|---|---|---|
name | str | = اسم عائلة الخط (مثالاً،., "Calibri", "Arial"). |
size | `int | float` |
color | str | = لون الخط كسلسلة سداسية عشرية بصيغة RRGGBB (مثالاً،., "FF0000" = للون الأحمر). |
bold | bool | True = لتطبيق الوزن العريض. |
italic | bool | True = لتطبيق النمط المائل. |
underline | bool | True = لتطبيق خط سفلي واحد. |
strikethrough | bool | True لتطبيق الخط المشطوب. |
Properties
Properties
Fill(pattern_type='none', foreground_color='FFFFFFFF', background_color='FFFFFFFF')Properties
| Properties | Properties | Properties |
|---|---|---|
pattern_type | str | نوع نمط التعبئة (مثال,., 'solid', 'none', 'darkGray'). |
foreground_color | str | لون المقدمة بصيغة سداسي عشرية RRGGBB. |
background_color | str | لون الخلفية بصيغة سداسي عشرية RRGGBB. |
Properties
set_solid_fill
fill.set_solid_fill(color: str)يطبق تعبئة صلبة باللون RRGGBB المحدد.
set_gradient_fill
fill.set_gradient_fill(start_color: str, end_color: str)يطبق تعبئة تدرج لوني من لونين.
set_pattern_fill
fill.set_pattern_fill(pattern_type: str, fg_color: str, bg_color: str)يطبق تعبئة بنمط مع ألوان أمامية وخلفية صريحة.
set_no_fill
fill.set_no_fill()يزيل أي تعبئة من الخلية.
Properties
Properties
Border(line_style='none', color='FF000000', weight=1)Properties
| Properties | Properties | Properties |
|---|---|---|
line_style | str | نمط خط الحدود: 'none', 'thin', 'medium', 'thick', 'dashed', 'dotted', 'double'. |
color | str | لون الحد بصيغة سداسي عشرية RRGGBB. |
weight | int | سُمك الحد (السمك) كعدد صحيح. |
Properties
Properties
Borders()حاوية لجميع حدود الخلية الأربعة بالإضافة إلى الحدود القطرية.
Properties
| Properties | Properties | Properties |
|---|---|---|
top | Border | إعدادات الحد العلوي. |
bottom | Border | إعدادات الحد السفلي. |
left | Border | إعدادات الحد الأيسر. |
right | Border | إعدادات الحد الأيمن. |
diagonal | Border | إعدادات الحد القطري. |
diagonal_up | bool | True لرسم الخط القطري الصاعد. |
diagonal_down | bool | True لرسم الخط القطري الهابط. |
Properties
Properties
Alignment(horizontal='general', vertical='bottom', wrap_text=False, indent=0, text_rotation=0, shrink_to_fit=False)Properties
| Properties | Properties | Properties |
|---|---|---|
horizontal | str | محاذاة أفقية: 'general', 'left', 'center', 'right', 'fill', 'justify', 'centerContinuous', 'distributed'. |
vertical | str | محاذاة عمودية: 'top', 'center', 'bottom', 'justify', 'distributed'. |
wrap_text | bool | True لتغليف النص داخل الخلية. |
indent | int | مستوى المسافة البادئة (0–15). |
text_rotation | int | دوران النص بالدرجات (0–180 أو 255 للتكديس). |
shrink_to_fit | bool | True لتقليص النص ليتناسب مع الخلية. |
NumberFormat
NumberFormat هي فئة مساعدة تحتوي على طرق ثابتة فقط. لا يتم إنشاء كائن منها مباشرة.
الطرق الثابتة
get_builtin_format
NumberFormat.get_builtin_format(format_id: int) -> strتُرجع سلسلة رمز التنسيق للمعرف المدمج للتنسيق المعطى (مثال،., NumberFormat.get_builtin_format(9) تُرجع "0%").
is_builtin_format
NumberFormat.is_builtin_format(format_code: str) -> boolProperties True إذا كان رمز التنسيق المعطى يطابق تنسيق Excel مدمج معروف.
lookup_builtin_format
NumberFormat.lookup_builtin_format(format_code: str) -> int | Noneتُرجع معرف التنسيق المدمج لسلسلة رمز التنسيق، أو None إذا لم يكن الرمز تنسيقًا مدمجًا.
Properties
Properties
Protection(locked=True, hidden=False)Properties
| Properties | Properties | Properties |
|---|---|---|
locked | bool | True يعني أن الخلية مقفلة عندما تكون حماية ورقة العمل مفعلة (افتراضي). |
hidden | bool | True يعني أن أي صيغة في الخلية تُخفى في شريط الصيغ عندما تكون حماية ورقة العمل مفعلة. |
Properties
المثال التالي ينسق خلية عنوان بخط عريض أحمر، خلفية صفراء، وحدود سوداء رقيقة على جميع الجوانب.
from aspose.cells_foss import Workbook
wb = Workbook()
ws = wb.worksheets[0]
ws.cells["A1"].put_value("Total Revenue")
style = ws.cells["A1"].get_style()
# Bold red font
style.font.bold = True
style.font.color = "FF0000" # red
style.font.size = 13
# Yellow solid fill
style.set_fill_color("FFFF00")
# Thin black border on all four sides
for side in ("top", "bottom", "left", "right"):
style.set_border(side, line_style="thin", color="000000", weight=1)
# Center the text
style.set_horizontal_alignment("center")
ws.cells["A1"].apply_style(style)
wb.save("styled.xlsx")