Table
aspose-cells-foss يمثل جداول Excel المهيكلة (ListObjects) من خلال Table الفئة و TableCollection متاح كـ ws.list_objects. توفر الجداول نطاقات مسماة، وتصفية تلقائية، وصفوف رأسية، وتنسيق صفوف متناوب مدمج في تنسيق XLSX.
Properties: aspose.cells_foss
from aspose.cells_foss import TableStyleInfo, TableColumnTableStyleInfo
يصف النمط البصري المطبق على الجدول (التنقيط، تمييز العمود الأول/الأخير).
Properties
TableStyleInfo()Properties
| Properties | Properties | Properties |
|---|---|---|
name | str | اسم نمط جدول Excel (مثالاً،., "TableStyleMedium9"). |
show_first_column | bool | True لتطبيق تنسيق خاص على العمود الأول. |
show_last_column | bool | True لتطبيق تنسيق خاص على العمود الأخير. |
show_row_stripes | bool | True لتطبيق تظليل صفوف متناوب. |
show_column_stripes | bool | True لتطبيق تظليل أعمدة متناوب. |
TableColumn
يصف عمودًا واحدًا داخل الجدول.
Properties
TableColumn(col_id: int, name: str)| Properties | Properties | Properties |
|---|---|---|
col_id | int | 1-based column identifier within the table (not the worksheet column index). |
name | str | نص عنوان العمود. يجب أن يكون فريداً داخل الجدول. |
Properties
| Properties | Properties | Properties |
|---|---|---|
id | int | معرّف العمود (للقراءة فقط). |
name | str | نص عنوان العمود. |
totals_row_function | str | دالة التجميع المعروضة في صف الإجماليات: 'none', 'sum', 'average', 'count', 'countNums', 'max', 'min', 'stdDev', 'var', 'custom'. |
totals_row_label | str | نص التسمية المعروض في خلية الإجماليات عندما totals_row_function يكون 'none'. |
totals_row_formula | str | الصيغة المخصصة المستخدمة عندما totals_row_function يكون 'custom'. |
Properties
Table الكائنات لا تُنشأ مباشرة. استخدم ws.list_objects.add(...) أو ws.list_objects.add_with_range(...).
Properties
| Properties | Properties | Properties |
|---|---|---|
name | str | اسم الجدول الداخلي (يجب أن يكون فريدًا في المصنف، بدون مسافات). |
display_name | str | اسم العرض المعروض في مربع اسم Excel. |
ref | str | نطاق الخلايا الذي تغطيه الجدول (مثالاً،., "A1:D10"). |
has_headers | bool | True إذا كان الصف الأول من النطاق يحتوي على رؤوس الأعمدة. |
show_totals_row | bool | True لعرض صف إجماليات التجميع في أسفل الجدول. |
show_auto_filter | bool | True لإظهار أسهم القائمة المنسدلة للتصفية التلقائية في صف الرأس. |
table_style_info | TableStyleInfo | إعدادات النمط البصري (التنقيط، تمييز الأعمدة). |
columns | list[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() للنطاقات المكتوبة صراحةً.
الخصائص والتكرار
| Properties | Properties |
|---|---|
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")