Table

aspose-cells-foss يمثل جداول Excel المهيكلة (ListObjects) من خلال Table الفئة و TableCollection متاح كـ ws.list_objects. توفر الجداول نطاقات مسماة، وتصفية تلقائية، وصفوف رأسية، وتنسيق صفوف متناوب مدمج في تنسيق XLSX.

Properties: aspose.cells_foss

from aspose.cells_foss import TableStyleInfo, TableColumn

TableStyleInfo

يصف النمط البصري المطبق على الجدول (التنقيط، تمييز العمود الأول/الأخير).

Properties

TableStyleInfo()

Properties

PropertiesPropertiesProperties
namestrاسم نمط جدول Excel (مثالاً،., "TableStyleMedium9").
show_first_columnboolTrue لتطبيق تنسيق خاص على العمود الأول.
show_last_columnboolTrue لتطبيق تنسيق خاص على العمود الأخير.
show_row_stripesboolTrue لتطبيق تظليل صفوف متناوب.
show_column_stripesboolTrue لتطبيق تظليل أعمدة متناوب.

TableColumn

يصف عمودًا واحدًا داخل الجدول.

Properties

TableColumn(col_id: int, name: str)
PropertiesPropertiesProperties
col_idint1-based column identifier within the table (not the worksheet column index).
namestrنص عنوان العمود. يجب أن يكون فريداً داخل الجدول.

Properties

PropertiesPropertiesProperties
idintمعرّف العمود (للقراءة فقط).
namestrنص عنوان العمود.
totals_row_functionstrدالة التجميع المعروضة في صف الإجماليات: 'none', 'sum', 'average', 'count', 'countNums', 'max', 'min', 'stdDev', 'var', 'custom'.
totals_row_labelstrنص التسمية المعروض في خلية الإجماليات عندما totals_row_function يكون 'none'.
totals_row_formulastrالصيغة المخصصة المستخدمة عندما totals_row_function يكون 'custom'.

Properties

Table الكائنات لا تُنشأ مباشرة. استخدم ws.list_objects.add(...) أو ws.list_objects.add_with_range(...).

Properties

PropertiesPropertiesProperties
namestrاسم الجدول الداخلي (يجب أن يكون فريدًا في المصنف، بدون مسافات).
display_namestrاسم العرض المعروض في مربع اسم Excel.
refstrنطاق الخلايا الذي تغطيه الجدول (مثالاً،., "A1:D10").
has_headersboolTrue إذا كان الصف الأول من النطاق يحتوي على رؤوس الأعمدة.
show_totals_rowboolTrue لعرض صف إجماليات التجميع في أسفل الجدول.
show_auto_filterboolTrue لإظهار أسهم القائمة المنسدلة للتصفية التلقائية في صف الرأس.
table_style_infoTableStyleInfoإعدادات النمط البصري (التنقيط، تمييز الأعمدة).
columnslist[TableColumn]قائمة مرتبة من TableColumn الكائنات (واحد لكل عمود في الجدول).

TableCollection

TableCollection يتم الوصول إليه كـ ws.list_objects. يدير جميع الجداول المهيكلة في ورقة العمل.

Properties

add

ws.list_objects.add(
    start_row: int,
    start_col: int,
    end_row: int,
    end_col: int,
    has_headers: bool = True,
    name: str | None = None
) -> Table

ينشئ جدولًا فوق نطاق الخلايا المحدد. جميع الفهارس هي 0-based. إذا name هي None,، يتم إنشاء اسم تلقائيًا (مثالًا،., "Table1").

add_with_range

ws.list_objects.add_with_range(
    cell_range: str,
    name: str | None = None,
    has_headers: bool = True
) -> Table

ينشئ جدولًا من سلسلة نطاق بنمط A1 (مثالًا،., "A1:D10"). أكثر قابلية للقراءة من add() للنطاقات المكتوبة صراحةً.

الخصائص والتكرار

PropertiesProperties
countعدد الجداول في ورقة العمل هذه (للقراءة فقط).
__len__()Properties count.
__iter__()يتكرر على جميع Table الكائنات.
__getitem__(index)يرْجع الـ Table في الصفرية index.

Properties

المثال التالي يكتب مجموعة بيانات مخزون المنتجات ويحولها إلى جدول Excel منسق مع صف إجماليات.

from aspose.cells_foss import Workbook

wb = Workbook()
ws = wb.worksheets[0]
ws.name = "Inventory"

# Write header and data rows
headers = ["SKU", "Product", "Qty", "Unit Price"]
rows = [
    ["A001", "Widget Alpha", 150, 12.99],
    ["A002", "Widget Beta",   80, 24.50],
    ["A003", "Gadget Gamma",  45, 49.99],
    ["A004", "Gadget Delta",  210, 8.75],
]

for col, h in enumerate(headers):
    ws.cells[0][col].put_value(h)
for row_i, row in enumerate(rows, start=1):
    for col_i, val in enumerate(row):
        ws.cells[row_i][col_i].put_value(val)

# Create a table over A1:D5
table = ws.list_objects.add_with_range("A1:D5", name="InventoryTable")

# Configure style
table.table_style_info.name = "TableStyleMedium9"
table.table_style_info.show_row_stripes = True
table.table_style_info.show_first_column = False
table.table_style_info.show_last_column = False

# Add a totals row with sum on Qty and Unit Price columns
table.show_totals_row = True
table.columns[2].totals_row_function = "sum"    # Qty
table.columns[3].totals_row_function = "sum"    # Unit Price
table.columns[0].totals_row_label = "Total"

wb.save("inventory_table.xlsx")

انظر أيضًا

 العربية